1
1
import { SignatureHelpParams } from "vscode-languageserver/node" ;
2
2
3
3
import type { ServerManager } from "../ServerManager" ;
4
- import type { ComplexToken , FunctionComplexToken } from "../Tokenizer/types" ;
4
+ import type { FunctionComplexToken } from "../Tokenizer/types" ;
5
5
import { LanguageScopes } from "../Tokenizer/constants" ;
6
6
import { TokenizedScope } from "../Tokenizer/Tokenizer" ;
7
7
import { SignatureHelpBuilder } from "./Builders" ;
@@ -19,44 +19,26 @@ export default class SignatureHelpProvider extends Provider {
19
19
const {
20
20
textDocument : { uri } ,
21
21
position,
22
- context,
23
22
} = params ;
24
23
25
24
const liveDocument = this . server . liveDocumentsManager . get ( uri ) ;
26
25
const document = this . server . documentsCollection . getFromUri ( uri ) ;
27
26
if ( ! liveDocument || ! document ) return ;
28
27
29
- const tokenizedResult = this . server . tokenizer . isInLanguageScope ( liveDocument . getText ( ) , position , LanguageScopes . functionCall ) ;
30
- if ( ! tokenizedResult ) return ;
28
+ const [ lines , rawTokenizedContent ] = this . server . tokenizer . tokenizeContentToRaw ( liveDocument . getText ( ) ) ;
29
+ const line = lines [ position . line ] ;
30
+ const tokensArray = rawTokenizedContent [ position . line ] ;
31
31
32
- const functionIdentifier = this . server . tokenizer . findIdentiferFromPositionForLanguageScopes ( tokenizedResult . line , tokenizedResult . tokensArray , position , [
33
- LanguageScopes . functionCall ,
34
- LanguageScopes . functionIdentifier ,
35
- ] ) ;
36
- const activeParameter = this . server . tokenizer . getLanguageScopeOccurencesFromPositionWithDelimiter (
37
- tokenizedResult . tokensArray ,
38
- position ,
39
- LanguageScopes . separatorStatement ,
40
- LanguageScopes . leftArgumentsRoundBracket ,
41
- ) ;
42
-
43
- if ( context ?. isRetrigger && context . activeSignatureHelp ) {
44
- const { activeSignature, signatures } = context ?. activeSignatureHelp ;
32
+ if ( ! tokensArray || ! this . server . tokenizer . isInScope ( tokensArray , position , LanguageScopes . functionCall ) ) return ;
45
33
46
- if ( activeSignature && functionIdentifier === this . server . tokenizer . findFirstIdentiferForLanguageScope ( signatures [ activeSignature ] . label , LanguageScopes . functionIdentifier ) ) {
47
- return {
48
- signatures,
49
- activeSignature,
50
- activeParameter : activeParameter || null ,
51
- } ;
52
- }
53
- }
34
+ const rawContent = this . server . tokenizer . getLookBehindScopesRawContent ( line , tokensArray , position , [ LanguageScopes . functionCall , LanguageScopes . functionIdentifier ] ) ;
35
+ const activeParameter = this . server . tokenizer . getLookBehindScopeOccurences ( tokensArray , position , LanguageScopes . separatorStatement , LanguageScopes . leftArgumentsRoundBracket ) ;
54
36
55
37
const localScope = this . server . tokenizer . tokenizeContent ( liveDocument . getText ( ) , TokenizedScope . local , 0 , position . line ) ;
56
38
const functionComplexToken =
57
- localScope . functionsComplexTokens . find ( ( token ) => token . identifier === functionIdentifier ) ||
58
- document . getGlobalComplexTokens ( ) . find ( ( token ) => token . identifier === functionIdentifier ) ||
59
- this . getStandardLibComplexTokens ( ) . find ( ( token ) => token . identifier === functionIdentifier ) ;
39
+ localScope . functionsComplexTokens . find ( ( token ) => token . identifier === rawContent ) ||
40
+ document . getGlobalComplexTokens ( ) . find ( ( token ) => token . identifier === rawContent ) ||
41
+ this . getStandardLibComplexTokens ( ) . find ( ( token ) => token . identifier === rawContent ) ;
60
42
61
43
if ( functionComplexToken ) {
62
44
return SignatureHelpBuilder . buildFunctionItem ( functionComplexToken as FunctionComplexToken , activeParameter ) ;
0 commit comments