1
- import { CompletionItem , CompletionItemKind , CompletionItemTag , CompletionParams , InsertTextFormat , Position , Range , TextEdit } from 'vscode-languageserver/node' ;
1
+ import { CompletionItem , CompletionItemKind , CompletionItemTag , CompletionParams , InsertTextFormat , MarkupKind , Position , Range , TextEdit } from 'vscode-languageserver/node' ;
2
2
import { getServerSpec , getLanguageServerSettings , getMacroContext , makeRESTRequest , normalizeSystemName , getImports , findFullRange , getClassMemberContext , quoteUDLIdentifier , documaticHtmlToMarkdown , determineClassNameParameterClass , storageKeywordsKeyForToken , getParsedDocument , currentClass , normalizeClassname } from '../utils/functions' ;
3
3
import { ServerSpec , QueryData , KeywordDoc , MacroContext , compressedline } from '../utils/types' ;
4
4
import { documents , corePropertyParams } from '../utils/variables' ;
@@ -759,20 +759,24 @@ export async function onCompletion(params: CompletionParams): Promise<Completion
759
759
}
760
760
761
761
// Scan up through the file, looking for macro definitions
762
+ const undefs : string [ ] = [ ] ;
762
763
for ( let ln = params . position . line - 1 ; ln >= 0 ; ln -- ) {
763
- if ( parsed [ ln ] . length < 4 ) {
764
- continue ;
765
- }
766
- if ( parsed [ ln ] [ 0 ] . l == ld . cos_langindex && parsed [ ln ] [ 0 ] . s == ld . cos_ppc_attrindex ) {
764
+ if ( ! parsed [ ln ] ?. length ) continue ;
765
+ if ( parsed [ ln ] . length > 1 && parsed [ ln ] [ 0 ] . l == ld . cos_langindex && parsed [ ln ] [ 0 ] . s == ld . cos_ppc_attrindex ) {
767
766
// This line begins with a preprocessor command
768
767
const ppctext = doc . getText ( Range . create (
769
768
ln , parsed [ ln ] [ 1 ] . p ,
770
769
ln , parsed [ ln ] [ 1 ] . p + parsed [ ln ] [ 1 ] . c
771
770
) ) . toLowerCase ( ) ;
772
- if ( ppctext == "define" || ppctext == "def1arg" ) {
771
+ if ( parsed [ ln ] . length > 3 && [ "define" , "def1arg" ] . includes ( ppctext ) ) {
773
772
// This is a macro definition
773
+ const macro = doc . getText ( Range . create ( ln , parsed [ ln ] [ 2 ] . p , ln , parsed [ ln ] [ 2 ] . p + parsed [ ln ] [ 2 ] . c ) ) ;
774
+ if ( undefs . includes ( macro ) ) {
775
+ // Don't suggest this macro because it was #undef'd before the completion line
776
+ continue ;
777
+ }
774
778
const macrodef : CompletionItem = {
775
- label : doc . getText ( Range . create ( ln , parsed [ ln ] [ 2 ] . p , ln , parsed [ ln ] [ 2 ] . p + parsed [ ln ] [ 2 ] . c ) ) ,
779
+ label : macro ,
776
780
kind : CompletionItemKind . Text ,
777
781
data : [ "macro" , doc . uri ]
778
782
} ;
@@ -830,7 +834,7 @@ export async function onCompletion(params: CompletionParams): Promise<Completion
830
834
}
831
835
if ( docstr != macrodef . label ) {
832
836
macrodef . documentation = {
833
- kind : "plaintext" ,
837
+ kind : MarkupKind . PlainText ,
834
838
value : docstr
835
839
} ;
836
840
}
@@ -852,14 +856,18 @@ export async function onCompletion(params: CompletionParams): Promise<Completion
852
856
const valmatchres = restofline . match ( valregex ) ;
853
857
if ( valmatchres !== null ) {
854
858
macrodef . documentation = {
855
- kind : "plaintext" ,
859
+ kind : MarkupKind . PlainText ,
856
860
value : docstr + "\n" + valmatchres [ 1 ]
857
861
} ;
858
862
}
859
863
}
860
864
result . push ( macrodef ) ;
865
+ } else if ( parsed [ ln ] . length > 2 && ppctext == "undef" ) {
866
+ // This is a macro un-definition
867
+ undefs . push ( doc . getText ( Range . create ( ln , parsed [ ln ] [ 2 ] . p , ln , parsed [ ln ] [ 2 ] . p + parsed [ ln ] [ 2 ] . c ) ) ) ;
861
868
}
862
869
}
870
+ if ( parsed [ ln ] . some ( ( t ) => t . l == ld . cls_langindex ) ) break ;
863
871
}
864
872
}
865
873
else if ( prevline . slice ( - 1 ) === "$" && prevline . charAt ( prevline . length - 2 ) !== "$" && triggerlang === ld . cos_langindex ) {
@@ -2127,7 +2135,7 @@ export async function onCompletionResolve(item: CompletionItem): Promise<Complet
2127
2135
if ( respdata !== undefined && respdata . data . result . content . length > 0 ) {
2128
2136
// The class was found
2129
2137
item . documentation = {
2130
- kind : "markdown" ,
2138
+ kind : MarkupKind . Markdown ,
2131
2139
value : documaticHtmlToMarkdown ( respdata . data . result . content [ 0 ] . Description )
2132
2140
} ;
2133
2141
}
@@ -2156,7 +2164,7 @@ export async function onCompletionResolve(item: CompletionItem): Promise<Complet
2156
2164
defstr = defstr . concat ( parts [ 0 ] , "\n" , parts . slice ( 1 ) . join ( ) ) ;
2157
2165
}
2158
2166
item . documentation = {
2159
- kind : "plaintext" ,
2167
+ kind : MarkupKind . PlainText ,
2160
2168
value : defstr
2161
2169
} ;
2162
2170
}
0 commit comments