inherit cstyle... trying to figure out best end marker

This commit is contained in:
sevin7676 2015-04-18 07:29:10 -04:00
commit 184df6d18e
3 changed files with 56 additions and 96 deletions

View file

@ -7,26 +7,43 @@
-- =============================================
CREATE PROCEDURE dbo.TestProcedure
--#region parameters
@vint INT = 1, @vdate DATE = NULL, @vdatetime DATETIME = DATEADD (dd, 1, GETDATE())
--#endregion
--region parameters
@vint INT = 1
,@vdate DATE = NULL
,@vdatetime DATETIME = DATEADD (dd, 1, GETDATE())
,@vvarchar VARCHAR(MAX) = ''
--endregion
AS
BEGIN
/*#region set statements */
/*region set statements */
SET NOCOUNT ON;
SET XACT_ABORT ON;
SET QUOTED_IDENTIFIER ON;
/*#endregion*/
/*endregion*/
/**
* These comments will produce a fold widget
*/
SET @vint = CASE
WHEN @vdate IS NULL
THEN 1
ELSE 2
END
WHEN @vdate IS NULL
THEN 1
ELSE 2
END
IF @vint = 1
BEGIN
SET @vvarchar='one'
SET @vint = DATEDIFFT(dd, @vdate, @vdatetime)
END
SELECT Orders.OrderID, Customers.CompanyName, DATEFROMPARTS(YEAR(GETDATE()), 1, 1) AS FirstDayOfYear
SELECT Orders.OrderID
,Customers.CompanyName
,DATEFROMPARTS(YEAR(GETDATE()), 1, 1) AS FirstDayOfYear
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID = Customers.CustomerID

View file

@ -158,12 +158,16 @@ oop.inherits(FoldMode, BaseFoldMode);
return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
};
/**
* gets comment region block with end region assumed to be start of comment in any cstyle mode or SQL mode (--) which inherits from this.
* There may optionally be a pound symbol before the region/endregion statement
*/
this.getCommentRegionBlock = function(session, line, row) {
var startColumn = line.search(/\s*$/);
var maxRow = session.getLength();
var startRow = row;
var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
var depth = 1;
while (++row < maxRow) {
line = session.getLine(row);

View file

@ -33,42 +33,28 @@ define(function(require, exports, module) {
var oop = require("../../lib/oop");
var Range = require("../../range").Range;
var BaseFoldMode = require("./fold_mode").FoldMode;
var BaseFoldMode = require("./cstyle").FoldMode;
var FoldMode = exports.FoldMode = function() {};
oop.inherits(FoldMode, BaseFoldMode);
(function() {
/**
* Inheriting cstyle folding because it handles the region comment folding
* and special block comment folding appropriately.
*
* Cstyle's getCommentRegionBlock() contains the sql comment characters '--'.
*/
// Currently the only supported folding is #region comments
// TODO: add more folding (will require in depth testing because this has never existed before) for things like:
// CASE ... END https://msdn.microsoft.com/en-us/library/ms181765.aspx
// BEGIN ... END https://msdn.microsoft.com/en-us/library/ms182717.aspx
// -- LEFT OFF TRYING TO ADD ADVANCED FOLDING... UNCOMMENT TO CONTINUE
this.foldingStartMarker = /(\bCASE\b|\bBEGIN\b)|^\s*(\/\*)/i;
this.foldingStopMarker = /^(\bEND\b)|^[\s\*]*(\*\/)/i;
// this.foldingStopMarker = /^(?!\bCASE\b|\bBEGIN\b)(\bEND\b)|^[\s\*]*(\*\/)/i;
// this.foldingStopMarker = /^(?!\bCASE\b|\bBEGIN\b).*(\bEND\b)|^[\s\*]*(\*\/)/i;
//this.foldingStartMarker = /\bCASE\b|\bBEGIN\b/i;
this.foldingStartMarker = /(\bCASE\b|\bBEGIN\b)|^\s*(\/\*)/;
this.foldingStopMarker = /\bEND\b/i;
this.startRegionRe = /^\s*(\/\*|--)#?region\b/;
this.startRegionRe = /^\s*(\/\*|--)#region\b/;
this._getFoldWidgetBase = this.getFoldWidget;
this.getFoldWidget = function(session, foldStyle, row) {
var line = session.getLine(row);
var fw = this._getFoldWidgetBase(session, foldStyle, row);
if (!fw && this.startRegionRe.test(line))
return "start";
return fw;
};
//this is called when a fold widget is clicked
this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
var line = session.getLine(row);
@ -77,17 +63,17 @@ oop.inherits(FoldMode, BaseFoldMode);
var match = line.match(this.foldingStartMarker);
if (match) {
var i = match.index;
//if first capturing group, then match is for bracket, either '{' or '[', which match[1] will contain
if (match[1]) return this.getEndBlock(session, row, i, match[1]);
//return this.openingBracketBlock(session, match[1], row, i);
//if first capturing group (CASE|BEGIN)
if (match[1]) return this.getBeginEndBlock(session, row, i, match[1]);
//still going: match is for second capturing group, which is blockcomment
var range = session.getCommentFoldRange(row, i + match[0].length, 1);
console.log('getCommentFoldRange',range);
if (range && !range.isMultiLine()) {
if (forceMultiline) {
range = this.getSectionRange(session, row);
console.log('getSectionRange',range);
}
else if (foldStyle != "all") range = null;
}
@ -95,85 +81,38 @@ oop.inherits(FoldMode, BaseFoldMode);
return range;
}
//no support for end folding markers yet
if (foldStyle === "markbegin") return;
/* this is when end fold has marker, and user clicks it, in which case we want to find the opening braket
var match = line.match(this.foldingStopMarker);
if (match) {
var i = match.index + match[0].length;
if (match[1]) return this.closingBracketBlock(session, match[1], row, i);
return session.getCommentFoldRange(row, i, - 1);
}*/
return;
};
/**
* finds the next 'END' for closing a fold range
* @returns {range} folding block for sequence that starts with 'CASE' or 'BEGIN' and ends with 'END'
* @param {string} matchSequence - the sequence of charaters that started the fold widget, which should remain visible when the fold widget is folded
*/
this.getEndBlock = function(session, row, column, matchSequence) {
this.getBeginEndBlock = function(session, row, column, matchSequence) {
var start = {
row: row,
column: column + matchSequence.length
};
var maxRow = session.getLength();
var line;
var depth = 1;
var re = /\bEND\b/i; ///^\s*(?:\/\*|--)#(end)?region\b/;
var re = /(\bCASE\b|\bBEGIN\b)|(\bEND\b)/i;
while (++row < maxRow) {
line = session.getLine(row);
var m = re.exec(line);
if (!m) continue;
if (m[0]) depth--;
else depth++;
if (m[1]) depth++;
else depth--;
if (!depth) break;
}
var endRow = row;
if (endRow > start.row) {
return new Range(start.row, start.column, endRow, line.length);
}
/* var end = session.$findClosingBracket(bracket, start, typeRe);
if (!end) return;
var fw = session.foldWidgets[end.row];
if (fw == null) fw = session.getFoldWidget(end.row);
if (fw == "start" && end.row > start.row) {
end.row--;
end.column = session.getLine(end.row).length;
}
return Range.fromPoints(start, end);*/
};
this.getCommentRegionBlock = function(session, line, row) {
var startColumn = line.search(/\s*$/);
var maxRow = session.getLength();
var startRow = row;
var re = /^\s*(?:\/\*|--)#(end)?region\b/;
var depth = 1;
while (++row < maxRow) {
line = session.getLine(row);
var m = re.exec(line);
if (!m) continue;
if (m[1]) depth--;
else depth++;
if (!depth) break;
}
var endRow = row;
if (endRow > startRow) {
return new Range(startRow, startColumn, endRow, line.length);
}
};
}).call(FoldMode.prototype);