-
Notifications
You must be signed in to change notification settings - Fork 511
Add option to show last line with syntax-aware code folding #1546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -478,6 +478,11 @@ | |
"default": true, | ||
"description": "Enables syntax based code folding. When disabled, the default indentation based code folding is used." | ||
}, | ||
"powershell.codeFolding.showLastLine": { | ||
"type": "boolean", | ||
"default": false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tylerl0706 @rkeithhill @glennsarti @RussPitcher Thoughts on this being the default? (Note as in the description below that this is VSCode's default) |
||
"description": "Shows the last line of a folded section similar to the default VSCode folding style. When disabled, the entire folded region is hidden." | ||
}, | ||
"powershell.codeFormatting.preset": { | ||
"type": "string", | ||
"enum": [ | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -101,10 +101,13 @@ class LineNumberRange { | |||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
public rangeKind: vscode.FoldingRangeKind; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
private settings: Settings.ISettings; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
constructor( | ||||||||||||||||||||||||
rangeKind: vscode.FoldingRangeKind, | ||||||||||||||||||||||||
) { | ||||||||||||||||||||||||
this.rangeKind = rangeKind; | ||||||||||||||||||||||||
this.settings = Settings.load(); | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to ensure that settings are only loaded once? Like passing them into the constructor? Or does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1. Settings should go into the constructor signature. Settings.load() has no side effects (that I know of) but in theory there could be some race conditions? |
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
|
@@ -121,6 +124,9 @@ class LineNumberRange { | |||||||||||||||||||||||
): LineNumberRange { | ||||||||||||||||||||||||
this.startline = document.positionAt(start.startIndex).line; | ||||||||||||||||||||||||
this.endline = document.positionAt(end.startIndex).line; | ||||||||||||||||||||||||
if (this.settings.codeFolding && this.settings.codeFolding.showLastLine) { | ||||||||||||||||||||||||
this.endline--; | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a guard here to make sure that endline is never less than startline There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Acutally, in retrospect. This is wrong place to do this. Because, changing the endline too early means the vscode-powershell/src/features/Folding.ts Line 153 in 7afec44
Instead it should replace vscode-powershell/src/features/Folding.ts Lines 160 to 162 in 7afec44
public toFoldingRange(settings:ISettings): vscode.FoldingRange {
if (settings.codeFolding && settings.codeFolding.showLastLine) {
return new vscode.FoldingRange(this.startline, this.endline - 1, this.rangeKind);
} else {
return new vscode.FoldingRange(this.startline, this.endline, this.rangeKind);
}
} And then change the vscode-powershell/src/features/Folding.ts Lines 255 to 261 in 7afec44
const settings = this.currentSettings();
return foldableRegions
// It's possible to have duplicate or overlapping ranges, that is, regions which have the same starting
// line number as the previous region. Therefore only emit ranges which have a different starting line
// than the previous range.
.filter((item, index, src) => index === 0 || item.startline !== src[index - 1].startline)
// Convert the internal representation into the VSCode expected type
.map((item) => item.toFoldingRange(settings));
}
private currentSettings(): ISettings { Settings.load(); } The private method |
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
return this; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause merge conflicts later on if we leave it in. If you put your summary from here into a commit message, it will make its way into the changelog.
Just stick the summary into a commit taking out the changelog entry is probably the easiest way to go. Otherwise there is also the
git commit --amend
->git push origin +branch
option.