@@ -14,11 +14,15 @@ import {
1414 PrepareRenameParams ,
1515 Range ,
1616 ReferenceParams ,
17+ Registration ,
18+ RegistrationRequest ,
1719 RenameParams ,
1820 ResultProgressReporter ,
1921 SemanticTokensRequest ,
2022 TextDocumentPositionParams ,
2123 TextDocumentSyncKind ,
24+ Unregistration ,
25+ UnregistrationRequest ,
2226 WorkDoneProgressReporter ,
2327 WorkspaceSymbolParams ,
2428} from "vscode-languageserver" ;
@@ -48,6 +52,7 @@ interface DocumentInfo {
4852const documentPool : Record < string , DocumentInfo > = { } ;
4953
5054let supportSASGetLibList = false ;
55+ let registeredAdvancedCapabilities = false ;
5156
5257const connection : Connection = createConnection ( ProposedFeatures . all ) ;
5358
@@ -81,15 +86,9 @@ connection.onInitialize((params) => {
8186 firstTriggerCharacter : "\n" ,
8287 moreTriggerCharacter : [ ";" ] ,
8388 } ,
84- definitionProvider : { workDoneProgress : true } ,
85- declarationProvider : { workDoneProgress : true } ,
86- typeDefinitionProvider : { workDoneProgress : true } ,
87- referencesProvider : { workDoneProgress : true } ,
8889 documentSymbolProvider : { workDoneProgress : true } ,
8990 workspaceSymbolProvider : { workDoneProgress : true } ,
9091 hoverProvider : { workDoneProgress : true } ,
91- documentHighlightProvider : { workDoneProgress : true } ,
92- renameProvider : { prepareProvider : true , workDoneProgress : true } ,
9392 completionProvider : {
9493 triggerCharacters : _pyrightLanguageProvider . getClientCapabilities ( )
9594 . hasVisualStudioExtensionsCapability
@@ -105,7 +104,6 @@ connection.onInitialize((params) => {
105104 triggerCharacters : [ "(" , "," , ")" ] ,
106105 workDoneProgress : true ,
107106 } ,
108- callHierarchyProvider : true ,
109107 workspace : {
110108 workspaceFolders : {
111109 supported : true ,
@@ -196,8 +194,10 @@ connection.onDocumentSymbol(async (params, token) => {
196194 const sasSymbols = languageService . getDocumentSymbols ( ) ;
197195 const pythonSymbols =
198196 ( await _pyrightLanguageProvider . onDocumentSymbol ( params , token ) ) ?? [ ] ;
197+ let hasPythonCode = false ;
199198 for ( const sasSymbol of sasSymbols ) {
200199 if ( sasSymbol . name ?. toUpperCase ( ) === "PROC PYTHON" ) {
200+ hasPythonCode = true ;
201201 for ( const pythonSymbol of pythonSymbols ) {
202202 if ( ! ( "range" in pythonSymbol ) ) {
203203 continue ;
@@ -208,6 +208,15 @@ connection.onDocumentSymbol(async (params, token) => {
208208 }
209209 }
210210 }
211+ if ( registeredAdvancedCapabilities ) {
212+ if ( ! hasPythonCode ) {
213+ unregisterAdvancedCapabilities ( connection ) ;
214+ }
215+ } else {
216+ if ( hasPythonCode ) {
217+ registerAdvancedCapabilities ( connection ) ;
218+ }
219+ }
211220 return sasSymbols ;
212221} ) ;
213222
@@ -574,3 +583,42 @@ const syncAllChangedDoc = () => {
574583 syncIfDocChange ( uri ) ;
575584 }
576585} ;
586+
587+ const advancedCapabilities = [
588+ "textDocument/declaration" ,
589+ "textDocument/definition" ,
590+ "textDocument/typeDefinition" ,
591+ "textDocument/references" ,
592+ "textDocument/rename" ,
593+ "textDocument/documentHighlight" ,
594+ "textDocument/prepareCallHierarchy" ,
595+ ] ;
596+
597+ const registerAdvancedCapabilities = async ( conn : Connection ) => {
598+ if ( registeredAdvancedCapabilities ) {
599+ return ;
600+ }
601+ registeredAdvancedCapabilities = true ;
602+ const registerOptions = {
603+ documentSelector : [ { language : "sas" } ] ,
604+ } ;
605+ const registrations : Registration [ ] = [ ] ;
606+ for ( const capability of advancedCapabilities ) {
607+ registrations . push ( { id : capability , method : capability , registerOptions } ) ;
608+ }
609+ await conn . sendRequest ( RegistrationRequest . type , { registrations } ) ;
610+ } ;
611+
612+ const unregisterAdvancedCapabilities = ( conn : Connection ) => {
613+ if ( ! registeredAdvancedCapabilities ) {
614+ return ;
615+ }
616+ registeredAdvancedCapabilities = false ;
617+ const unregisterations : Unregistration [ ] = [ ] ;
618+ for ( const capability of advancedCapabilities ) {
619+ unregisterations . push ( { id : capability , method : capability } ) ;
620+ }
621+ conn . sendRequest ( UnregistrationRequest . type , {
622+ unregisterations : unregisterations ,
623+ } ) ;
624+ } ;
0 commit comments