@@ -28,6 +28,16 @@ public class LanguageServer
28
28
{
29
29
private static CancellationTokenSource existingRequestCancellation ;
30
30
31
+ private static readonly Location [ ] s_emptyLocationResult = new Location [ 0 ] ;
32
+
33
+ private static readonly CompletionItem [ ] s_emptyCompletionResult = new CompletionItem [ 0 ] ;
34
+
35
+ private static readonly SignatureInformation [ ] s_emptySignatureResult = new SignatureInformation [ 0 ] ;
36
+
37
+ private static readonly DocumentHighlight [ ] s_emptyHighlightResult = new DocumentHighlight [ 0 ] ;
38
+
39
+ private static readonly SymbolInformation [ ] s_emptySymbolResult = new SymbolInformation [ 0 ] ;
40
+
31
41
private ILogger Logger ;
32
42
private bool profilesLoaded ;
33
43
private bool consoleReplStarted ;
@@ -692,26 +702,20 @@ await editorSession.LanguageService.FindReferencesOfSymbol(
692
702
editorSession . Workspace . ExpandScriptReferences ( scriptFile ) ,
693
703
editorSession . Workspace ) ;
694
704
695
- Location [ ] referenceLocations = null ;
705
+ Location [ ] referenceLocations = s_emptyLocationResult ;
696
706
697
707
if ( referencesResult != null )
698
708
{
699
- referenceLocations =
700
- referencesResult
701
- . FoundReferences
702
- . Select ( r =>
703
- {
704
- return new Location
705
- {
706
- Uri = GetFileUri ( r . FilePath ) ,
707
- Range = GetRangeFromScriptRegion ( r . ScriptRegion )
708
- } ;
709
- } )
710
- . ToArray ( ) ;
711
- }
712
- else
713
- {
714
- referenceLocations = new Location [ 0 ] ;
709
+ var locations = new List < Location > ( ) ;
710
+ foreach ( SymbolReference foundReference in referencesResult . FoundReferences )
711
+ {
712
+ locations . Add ( new Location
713
+ {
714
+ Uri = GetFileUri ( foundReference . FilePath ) ,
715
+ Range = GetRangeFromScriptRegion ( foundReference . ScriptRegion )
716
+ } ) ;
717
+ }
718
+ referenceLocations = locations . ToArray ( ) ;
715
719
}
716
720
717
721
await requestContext . SendResult ( referenceLocations ) ;
@@ -734,24 +738,18 @@ await editorSession.LanguageService.GetCompletionsInFile(
734
738
cursorLine ,
735
739
cursorColumn ) ;
736
740
737
- CompletionItem [ ] completionItems = null ;
741
+ CompletionItem [ ] completionItems = s_emptyCompletionResult ;
738
742
739
743
if ( completionResults != null )
740
744
{
741
745
int sortIndex = 1 ;
742
- completionItems =
743
- completionResults
744
- . Completions
745
- . Select (
746
- c => CreateCompletionItem (
747
- c ,
748
- completionResults . ReplacedRange ,
749
- sortIndex ++ ) )
750
- . ToArray ( ) ;
751
- }
752
- else
753
- {
754
- completionItems = new CompletionItem [ 0 ] ;
746
+ var completions = new List < CompletionItem > ( ) ;
747
+ foreach ( CompletionDetails completion in completionResults . Completions )
748
+ {
749
+ CompletionItem completionItem = CreateCompletionItem ( completion , completionResults . ReplacedRange , sortIndex ) ;
750
+ sortIndex ++ ;
751
+ }
752
+ completionItems = completions . ToArray ( ) ;
755
753
}
756
754
757
755
await requestContext . SendResult ( completionItems ) ;
@@ -796,40 +794,35 @@ await editorSession.LanguageService.FindParameterSetsInFile(
796
794
textDocumentPositionParams . Position . Line + 1 ,
797
795
textDocumentPositionParams . Position . Character + 1 ) ;
798
796
799
- SignatureInformation [ ] signatures = null ;
800
- int ? activeParameter = null ;
801
- int ? activeSignature = 0 ;
797
+ SignatureInformation [ ] signatures = s_emptySignatureResult ;
802
798
803
799
if ( parameterSets != null )
804
800
{
805
- signatures =
806
- parameterSets
807
- . Signatures
808
- . Select ( s =>
809
- {
810
- return new SignatureInformation
811
- {
812
- Label = parameterSets . CommandName + " " + s . SignatureText ,
813
- Documentation = null ,
814
- Parameters =
815
- s . Parameters
816
- . Select ( CreateParameterInfo )
817
- . ToArray ( )
818
- } ;
819
- } )
820
- . ToArray ( ) ;
821
- }
822
- else
823
- {
824
- signatures = new SignatureInformation [ 0 ] ;
801
+ var sigs = new List < SignatureInformation > ( ) ;
802
+ foreach ( ParameterSetSignature sig in parameterSets . Signatures )
803
+ {
804
+ var parameters = new List < ParameterInformation > ( ) ;
805
+ foreach ( ParameterInfo paramInfo in sig . Parameters )
806
+ {
807
+ parameters . Add ( CreateParameterInfo ( paramInfo ) ) ;
808
+ }
809
+
810
+ var signature = new SignatureInformation
811
+ {
812
+ Label = parameterSets . CommandName + " " + sig . SignatureText ,
813
+ Documentation = null ,
814
+ Parameters = parameters . ToArray ( ) ,
815
+ } ;
816
+ }
817
+ signatures = sigs . ToArray ( ) ;
825
818
}
826
819
827
820
await requestContext . SendResult (
828
821
new SignatureHelp
829
822
{
830
823
Signatures = signatures ,
831
- ActiveParameter = activeParameter ,
832
- ActiveSignature = activeSignature
824
+ ActiveParameter = null ,
825
+ ActiveSignature = 0
833
826
} ) ;
834
827
}
835
828
@@ -847,26 +840,20 @@ protected async Task HandleDocumentHighlightRequest(
847
840
textDocumentPositionParams . Position . Line + 1 ,
848
841
textDocumentPositionParams . Position . Character + 1 ) ;
849
842
850
- DocumentHighlight [ ] documentHighlights = null ;
843
+ DocumentHighlight [ ] documentHighlights = s_emptyHighlightResult ;
851
844
852
845
if ( occurrencesResult != null )
853
846
{
854
- documentHighlights =
855
- occurrencesResult
856
- . FoundOccurrences
857
- . Select ( o =>
858
- {
859
- return new DocumentHighlight
860
- {
861
- Kind = DocumentHighlightKind . Write , // TODO: Which symbol types are writable?
862
- Range = GetRangeFromScriptRegion ( o . ScriptRegion )
863
- } ;
864
- } )
865
- . ToArray ( ) ;
866
- }
867
- else
868
- {
869
- documentHighlights = new DocumentHighlight [ 0 ] ;
847
+ var highlights = new List < DocumentHighlight > ( ) ;
848
+ foreach ( SymbolReference foundOccurrence in occurrencesResult . FoundOccurrences )
849
+ {
850
+ highlights . Add ( new DocumentHighlight
851
+ {
852
+ Kind = DocumentHighlightKind . Write , // TODO: Which symbol types are writable?
853
+ Range = GetRangeFromScriptRegion ( foundOccurrence . ScriptRegion )
854
+ } ) ;
855
+ }
856
+ documentHighlights = highlights . ToArray ( ) ;
870
857
}
871
858
872
859
await requestContext . SendResult ( documentHighlights ) ;
@@ -933,34 +920,29 @@ protected async Task HandleDocumentSymbolRequest(
933
920
editorSession . LanguageService . FindSymbolsInFile (
934
921
scriptFile ) ;
935
922
936
- SymbolInformation [ ] symbols = null ;
937
-
938
923
string containerName = Path . GetFileNameWithoutExtension ( scriptFile . FilePath ) ;
939
924
925
+ SymbolInformation [ ] symbols = s_emptySymbolResult ;
940
926
if ( foundSymbols != null )
941
927
{
942
- symbols =
943
- foundSymbols
944
- . FoundOccurrences
945
- . Select ( r =>
946
- {
947
- return new SymbolInformation
948
- {
949
- ContainerName = containerName ,
950
- Kind = GetSymbolKind ( r . SymbolType ) ,
951
- Location = new Location
952
- {
953
- Uri = GetFileUri ( r . FilePath ) ,
954
- Range = GetRangeFromScriptRegion ( r . ScriptRegion )
955
- } ,
956
- Name = GetDecoratedSymbolName ( r )
957
- } ;
958
- } )
959
- . ToArray ( ) ;
960
- }
961
- else
962
- {
963
- symbols = new SymbolInformation [ 0 ] ;
928
+ var symbolAcc = new List < SymbolInformation > ( ) ;
929
+ foreach ( SymbolReference foundOccurrence in foundSymbols . FoundOccurrences )
930
+ {
931
+ var location = new Location
932
+ {
933
+ Uri = GetFileUri ( foundOccurrence . FilePath ) ,
934
+ Range = GetRangeFromScriptRegion ( foundOccurrence . ScriptRegion )
935
+ } ;
936
+
937
+ symbolAcc . Add ( new SymbolInformation
938
+ {
939
+ ContainerName = containerName ,
940
+ Kind = GetSymbolKind ( foundOccurrence . SymbolType ) ,
941
+ Location = location ,
942
+ Name = GetDecoratedSymbolName ( foundOccurrence )
943
+ } ) ;
944
+ }
945
+ symbols = symbolAcc . ToArray ( ) ;
964
946
}
965
947
966
948
await requestContext . SendResult ( symbols ) ;
@@ -1011,26 +993,27 @@ protected async Task HandleWorkspaceSymbolRequest(
1011
993
1012
994
if ( foundSymbols != null )
1013
995
{
1014
- var matchedSymbols =
1015
- foundSymbols
1016
- . FoundOccurrences
1017
- . Where ( r => IsQueryMatch ( workspaceSymbolParams . Query , r . SymbolName ) )
1018
- . Select ( r =>
1019
- {
1020
- return new SymbolInformation
1021
- {
1022
- ContainerName = containerName ,
1023
- Kind = r . SymbolType == SymbolType . Variable ? SymbolKind . Variable : SymbolKind . Function ,
1024
- Location = new Location
1025
- {
1026
- Uri = GetFileUri ( r . FilePath ) ,
1027
- Range = GetRangeFromScriptRegion ( r . ScriptRegion )
1028
- } ,
1029
- Name = GetDecoratedSymbolName ( r )
1030
- } ;
1031
- } ) ;
1032
-
1033
- symbols . AddRange ( matchedSymbols ) ;
996
+ foreach ( SymbolReference foundOccurrence in foundSymbols . FoundOccurrences )
997
+ {
998
+ if ( ! IsQueryMatch ( workspaceSymbolParams . Query , foundOccurrence . SymbolName ) )
999
+ {
1000
+ continue ;
1001
+ }
1002
+
1003
+ var location = new Location
1004
+ {
1005
+ Uri = GetFileUri ( foundOccurrence . FilePath ) ,
1006
+ Range = GetRangeFromScriptRegion ( foundOccurrence . ScriptRegion )
1007
+ } ;
1008
+
1009
+ symbols . Add ( new SymbolInformation
1010
+ {
1011
+ ContainerName = containerName ,
1012
+ Kind = foundOccurrence . SymbolType == SymbolType . Variable ? SymbolKind . Variable : SymbolKind . Function ,
1013
+ Location = location ,
1014
+ Name = GetDecoratedSymbolName ( foundOccurrence )
1015
+ } ) ;
1016
+ }
1034
1017
}
1035
1018
}
1036
1019
0 commit comments