From db00ef70a197f18b9bb782b6df07859571de445a Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 5 Sep 2018 16:40:48 +1000 Subject: [PATCH 1/7] Remove reference request select call --- .../Server/LanguageServer.cs | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 7f8f223b4..c4d70839c 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -28,6 +28,8 @@ public class LanguageServer { private static CancellationTokenSource existingRequestCancellation; + private static Location[] s_emptyLocationResult = new Location[0]; + private ILogger Logger; private bool profilesLoaded; private bool consoleReplStarted; @@ -692,26 +694,20 @@ await editorSession.LanguageService.FindReferencesOfSymbol( editorSession.Workspace.ExpandScriptReferences(scriptFile), editorSession.Workspace); - Location[] referenceLocations = null; + Location[] referenceLocations = s_emptyLocationResult; if (referencesResult != null) { - referenceLocations = - referencesResult - .FoundReferences - .Select(r => - { - return new Location - { - Uri = GetFileUri(r.FilePath), - Range = GetRangeFromScriptRegion(r.ScriptRegion) - }; - }) - .ToArray(); - } - else - { - referenceLocations = new Location[0]; + var locations = new List(); + foreach (SymbolReference foundReference in referencesResult.FoundReferences) + { + locations.Add(new Location + { + Uri = GetFileUri(foundReference.FilePath), + Range = GetRangeFromScriptRegion(foundReference.ScriptRegion) + }); + } + referenceLocations = locations.ToArray(); } await requestContext.SendResult(referenceLocations); From cd1b7b6eee4ea6682869afea1d697006c57719c4 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 5 Sep 2018 16:45:30 +1000 Subject: [PATCH 2/7] Remove completion request select call --- .../Server/LanguageServer.cs | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index c4d70839c..ae384ba82 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -30,6 +30,8 @@ public class LanguageServer private static Location[] s_emptyLocationResult = new Location[0]; + private static CompletionItem[] s_emptyCompletionResult = new CompletionItem[0]; + private ILogger Logger; private bool profilesLoaded; private bool consoleReplStarted; @@ -730,24 +732,18 @@ await editorSession.LanguageService.GetCompletionsInFile( cursorLine, cursorColumn); - CompletionItem[] completionItems = null; + CompletionItem[] completionItems = s_emptyCompletionResult; if (completionResults != null) { int sortIndex = 1; - completionItems = - completionResults - .Completions - .Select( - c => CreateCompletionItem( - c, - completionResults.ReplacedRange, - sortIndex++)) - .ToArray(); - } - else - { - completionItems = new CompletionItem[0]; + var completions = new List(); + foreach (CompletionDetails completion in completionResults.Completions) + { + CompletionItem completionItem = CreateCompletionItem(completion, completionResults.ReplacedRange, sortIndex); + sortIndex++; + } + completionItems = completions.ToArray(); } await requestContext.SendResult(completionItems); From dfaa399eebe4f3a02b873766b2789eeb4f7303f5 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 5 Sep 2018 16:53:36 +1000 Subject: [PATCH 3/7] Remove signature request select calls --- .../Server/LanguageServer.cs | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index ae384ba82..177cd5f1b 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -28,9 +28,11 @@ public class LanguageServer { private static CancellationTokenSource existingRequestCancellation; - private static Location[] s_emptyLocationResult = new Location[0]; + private static readonly Location[] s_emptyLocationResult = new Location[0]; - private static CompletionItem[] s_emptyCompletionResult = new CompletionItem[0]; + private static readonly CompletionItem[] s_emptyCompletionResult = new CompletionItem[0]; + + private static readonly SignatureInformation[] s_emptySignatureResult = new SignatureInformation[0]; private ILogger Logger; private bool profilesLoaded; @@ -788,40 +790,35 @@ await editorSession.LanguageService.FindParameterSetsInFile( textDocumentPositionParams.Position.Line + 1, textDocumentPositionParams.Position.Character + 1); - SignatureInformation[] signatures = null; - int? activeParameter = null; - int? activeSignature = 0; + SignatureInformation[] signatures = s_emptySignatureResult; if (parameterSets != null) { - signatures = - parameterSets - .Signatures - .Select(s => - { - return new SignatureInformation - { - Label = parameterSets.CommandName + " " + s.SignatureText, - Documentation = null, - Parameters = - s.Parameters - .Select(CreateParameterInfo) - .ToArray() - }; - }) - .ToArray(); - } - else - { - signatures = new SignatureInformation[0]; + var sigs = new List(); + foreach (ParameterSetSignature sig in parameterSets.Signatures) + { + var parameters = new List(); + foreach (ParameterInfo paramInfo in sig.Parameters) + { + parameters.Add(CreateParameterInfo(paramInfo)); + } + + var signature = new SignatureInformation + { + Label = parameterSets.CommandName + " " + sig.SignatureText, + Documentation = null, + Parameters = parameters.ToArray(), + } + } + signatures = sigs.ToArray(); } await requestContext.SendResult( new SignatureHelp { Signatures = signatures, - ActiveParameter = activeParameter, - ActiveSignature = activeSignature + ActiveParameter = null, + ActiveSignature = 0 }); } From 37a4287a01849730580f7ea048fb0be54104069e Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 5 Sep 2018 16:56:50 +1000 Subject: [PATCH 4/7] Remove highlight request select call --- .../Server/LanguageServer.cs | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 177cd5f1b..179813101 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -34,6 +34,8 @@ public class LanguageServer private static readonly SignatureInformation[] s_emptySignatureResult = new SignatureInformation[0]; + private static readonly DocumentHighlight[] s_emptyHighlightResult = new DocumentHighlight[0]; + private ILogger Logger; private bool profilesLoaded; private bool consoleReplStarted; @@ -836,26 +838,20 @@ protected async Task HandleDocumentHighlightRequest( textDocumentPositionParams.Position.Line + 1, textDocumentPositionParams.Position.Character + 1); - DocumentHighlight[] documentHighlights = null; + DocumentHighlight[] documentHighlights = s_emptyHighlightResult; if (occurrencesResult != null) { - documentHighlights = - occurrencesResult - .FoundOccurrences - .Select(o => - { - return new DocumentHighlight - { - Kind = DocumentHighlightKind.Write, // TODO: Which symbol types are writable? - Range = GetRangeFromScriptRegion(o.ScriptRegion) - }; - }) - .ToArray(); - } - else - { - documentHighlights = new DocumentHighlight[0]; + var highlights = new List(); + foreach (SymbolReference foundOccurrence in occurrencesResult.FoundOccurrences) + { + highlights.Add(new DocumentHighlight + { + Kind = DocumentHighlightKind.Write, // TODO: Which symbol types are writable? + Range = GetRangeFromScriptRegion(foundOccurrence.ScriptRegion) + }); + } + documentHighlights = highlights.ToArray(); } await requestContext.SendResult(documentHighlights); From 5f07a7e735d2425d4ccda032c91d7622b64234fa Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 5 Sep 2018 17:01:30 +1000 Subject: [PATCH 5/7] Remove select call in document symbol request --- .../Server/LanguageServer.cs | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 179813101..827e57a76 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -36,6 +36,8 @@ public class LanguageServer private static readonly DocumentHighlight[] s_emptyHighlightResult = new DocumentHighlight[0]; + private static readonly SymbolInformation[] s_emptySymbolResult = new SymbolInformation[0]; + private ILogger Logger; private bool profilesLoaded; private bool consoleReplStarted; @@ -918,34 +920,29 @@ protected async Task HandleDocumentSymbolRequest( editorSession.LanguageService.FindSymbolsInFile( scriptFile); - SymbolInformation[] symbols = null; - string containerName = Path.GetFileNameWithoutExtension(scriptFile.FilePath); + SymbolInformation[] symbols = s_emptySymbolResult; if (foundSymbols != null) { - symbols = - foundSymbols - .FoundOccurrences - .Select(r => - { - return new SymbolInformation - { - ContainerName = containerName, - Kind = GetSymbolKind(r.SymbolType), - Location = new Location - { - Uri = GetFileUri(r.FilePath), - Range = GetRangeFromScriptRegion(r.ScriptRegion) - }, - Name = GetDecoratedSymbolName(r) - }; - }) - .ToArray(); - } - else - { - symbols = new SymbolInformation[0]; + var symbolAcc = new List(); + foreach (SymbolReference foundOccurrence in foundSymbols.FoundOccurrences) + { + var location = new Location + { + Uri = GetFileUri(foundOccurrence.FilePath), + Range = GetRangeFromScriptRegion(foundOccurrence.ScriptRegion) + }; + + symbolAcc.Add(new SymbolInformation + { + ContainerName = containerName, + Kind = GetSymbolKind(foundOccurrence.SymbolType), + Location = location, + Name = GetDecoratedSymbolName(foundOccurrence) + }); + } + symbols = symbolAcc.ToArray(); } await requestContext.SendResult(symbols); From 19ff7cd70f1c007d3a271cef3251ff92b4a7a6f2 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 5 Sep 2018 17:05:30 +1000 Subject: [PATCH 6/7] Remove linq in workspace symbol request --- .../Server/LanguageServer.cs | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 827e57a76..557687b93 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -993,26 +993,27 @@ protected async Task HandleWorkspaceSymbolRequest( if (foundSymbols != null) { - var matchedSymbols = - foundSymbols - .FoundOccurrences - .Where(r => IsQueryMatch(workspaceSymbolParams.Query, r.SymbolName)) - .Select(r => - { - return new SymbolInformation - { - ContainerName = containerName, - Kind = r.SymbolType == SymbolType.Variable ? SymbolKind.Variable : SymbolKind.Function, - Location = new Location - { - Uri = GetFileUri(r.FilePath), - Range = GetRangeFromScriptRegion(r.ScriptRegion) - }, - Name = GetDecoratedSymbolName(r) - }; - }); - - symbols.AddRange(matchedSymbols); + foreach (SymbolReference foundOccurrence in foundSymbols.FoundOccurrences) + { + if (!IsQueryMatch(workspaceSymbolParams.Query, foundOccurrence.SymbolType)) + { + continue; + } + + var location = new Location + { + Uri = GetFileUri(foundOccurrence.FilePath), + Range = GetRangeFromScriptRegion(foundOccurrence.ScriptRegion) + }; + + symbols.Add(new SymbolInformation + { + ContainerName = containerName, + Kind = foundOccurrence.SymbolType == SymbolType.Variable ? SymbolKind.Variable : SymbolKind.Function, + Location = location, + Name = GetDecoratedSymbolName(foundOccurrence) + }); + } } } From 9863c537c6a4be677144fddb62f1ff2a88926600 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 5 Sep 2018 17:11:32 +1000 Subject: [PATCH 7/7] Fix compile errors --- .../Server/LanguageServer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index 557687b93..b35a6a793 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -812,7 +812,7 @@ await editorSession.LanguageService.FindParameterSetsInFile( Label = parameterSets.CommandName + " " + sig.SignatureText, Documentation = null, Parameters = parameters.ToArray(), - } + }; } signatures = sigs.ToArray(); } @@ -995,7 +995,7 @@ protected async Task HandleWorkspaceSymbolRequest( { foreach (SymbolReference foundOccurrence in foundSymbols.FoundOccurrences) { - if (!IsQueryMatch(workspaceSymbolParams.Query, foundOccurrence.SymbolType)) + if (!IsQueryMatch(workspaceSymbolParams.Query, foundOccurrence.SymbolName)) { continue; }