Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 262
Add document symbols for #region#2003
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
216727a
Add `SymbolType.Region`
fflaten 085187f
Add `RegionDocumentSymbolProvider.cs`
fflaten fdde391
Optimize `CodeLens` providers
andyleejordan b4f2524
Miscellaneous clean-ups
andyleejordan 05acee2
Reduce unnecessary allocations and exceptions in handlers
andyleejordan a4bc2a1
Fix `ProvideCodeLenses` to not take useless `CancellationToken`
andyleejordan e16ca88
Pass `CancellationToken` through `SymbolDetails.CreateAsync()`
andyleejordan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1 src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6 src/PowerShellEditorServices/Services/CodeLens/ICodeLensProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 6 additions & 10 deletions
16 src/PowerShellEditorServices/Services/CodeLens/PesterCodeLensProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 4 additions & 9 deletions
13 src/PowerShellEditorServices/Services/CodeLens/ReferencesCodeLensProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5 src/PowerShellEditorServices/Services/PowerShell/Utility/CommandHelpers.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7 src/PowerShellEditorServices/Services/Symbols/PesterDocumentSymbolProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79 src/PowerShellEditorServices/Services/Symbols/RegionDocumentSymbolProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| using System.Collections.Generic; | ||
| using System.Management.Automation.Language; | ||
| using Microsoft.PowerShell.EditorServices.Services.TextDocument; | ||
| namespace Microsoft.PowerShell.EditorServices.Services.Symbols | ||
| { | ||
| /// <summary> | ||
| /// Provides an IDocumentSymbolProvider implementation for | ||
| /// enumerating regions as symbols in script (.psd1, .psm1) files. | ||
| /// </summary> | ||
| internal class RegionDocumentSymbolProvider : IDocumentSymbolProvider | ||
| { | ||
| string IDocumentSymbolProvider.ProviderId => nameof(RegionDocumentSymbolProvider); | ||
| IEnumerable<SymbolReference> IDocumentSymbolProvider.ProvideDocumentSymbols(ScriptFile scriptFile) | ||
| { | ||
| Stack<Token> tokenCommentRegionStack = new(); | ||
| Token[] tokens = scriptFile.ScriptTokens; | ||
| for (int i = 0; i < tokens.Length; i++) | ||
| { | ||
| Token token = tokens[i]; | ||
| // Exclude everything but single-line comments | ||
| if (token.Kind != TokenKind.Comment || | ||
| token.Extent.StartLineNumber != token.Extent.EndLineNumber || | ||
| !TokenOperations.IsBlockComment(i, tokens)) | ||
| { | ||
| continue; | ||
| } | ||
| // Processing for #region -> #endregion | ||
| if (TokenOperations.s_startRegionTextRegex.IsMatch(token.Text)) | ||
| { | ||
| tokenCommentRegionStack.Push(token); | ||
| continue; | ||
| } | ||
| if (TokenOperations.s_endRegionTextRegex.IsMatch(token.Text)) | ||
| { | ||
| // Mismatched regions in the script can cause bad stacks. | ||
| if (tokenCommentRegionStack.Count > 0) | ||
| { | ||
| Token regionStart = tokenCommentRegionStack.Pop(); | ||
| Token regionEnd = token; | ||
| BufferRange regionRange = new( | ||
| regionStart.Extent.StartLineNumber, | ||
| regionStart.Extent.StartColumnNumber, | ||
| regionEnd.Extent.EndLineNumber, | ||
| regionEnd.Extent.EndColumnNumber); | ||
| yield return new SymbolReference( | ||
| SymbolType.Region, | ||
| regionStart.Extent.Text.Trim().TrimStart('#'), | ||
| regionStart.Extent.Text.Trim(), | ||
| regionStart.Extent, | ||
| new ScriptExtent() | ||
| { | ||
| Text = string.Join(System.Environment.NewLine, scriptFile.GetLinesInRange(regionRange)), | ||
| StartLineNumber = regionStart.Extent.StartLineNumber, | ||
| StartColumnNumber = regionStart.Extent.StartColumnNumber, | ||
| StartOffset = regionStart.Extent.StartOffset, | ||
| EndLineNumber = regionEnd.Extent.EndLineNumber, | ||
| EndColumnNumber = regionEnd.Extent.EndColumnNumber, | ||
| EndOffset = regionEnd.Extent.EndOffset, | ||
| File = regionStart.Extent.File | ||
| }, | ||
| scriptFile, | ||
| isDeclaration: true); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
10 changes: 7 additions & 3 deletions
10 src/PowerShellEditorServices/Services/Symbols/SymbolDetails.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 13 additions & 5 deletions
18 src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 one is a big ol' "waiting on PSSA" right?