@@ -12,7 +12,37 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
12
12
token : vscode . CancellationToken ,
13
13
context : vscode . CompletionContext
14
14
) : vscode . ProviderResult < vscode . CompletionItem [ ] | vscode . CompletionList > {
15
- return this . dollarsComplete ( document , position ) || this . commands ( document , position ) ;
15
+ if ( context . triggerCharacter === '#' ) return this . macro ( document , position , token , context ) ;
16
+ return (
17
+ this . dollarsComplete ( document , position ) ||
18
+ this . commands ( document , position ) ||
19
+ this . macro ( document , position , token , context )
20
+ ) ;
21
+ }
22
+
23
+ macro (
24
+ document : vscode . TextDocument ,
25
+ position : vscode . Position ,
26
+ token : vscode . CancellationToken ,
27
+ context : vscode . CompletionContext
28
+ ) : vscode . ProviderResult < vscode . CompletionItem [ ] | vscode . CompletionList > {
29
+ let line = document . getText ( new vscode . Range ( new vscode . Position ( position . line , 0 ) , position ) ) ;
30
+ let range = new vscode . Range ( new vscode . Position ( position . line , line . indexOf ( '#' ) ) , position ) ;
31
+ if ( ! context . triggerCharacter && ! line . match ( / # + \b \w + \b $ / ) ) {
32
+ return null ;
33
+ }
34
+ return [
35
+ {
36
+ label : '##class()' ,
37
+ insertText : new vscode . SnippetString ( '##class($0)' ) ,
38
+ range
39
+ } ,
40
+ {
41
+ label : '##super()' ,
42
+ insertText : new vscode . SnippetString ( '##super($0)' ) ,
43
+ range
44
+ }
45
+ ] ;
16
46
}
17
47
18
48
commands (
@@ -24,7 +54,7 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
24
54
new vscode . Range ( new vscode . Position ( word . start . line , 0 ) , new vscode . Position ( word . end . line , word . end . character ) )
25
55
) ;
26
56
27
- if ( line . match ( / \s + \b [ a - z ] + \b / i) ) {
57
+ if ( line . match ( / ^ \s + \b [ a - z ] + \b $ / i) ) {
28
58
let search = line . trim ( ) . toUpperCase ( ) ;
29
59
let items = commands
30
60
. filter ( el => el . label . startsWith ( search ) || el . alias . findIndex ( el2 => el2 . startsWith ( search ) ) >= 0 )
@@ -33,7 +63,7 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
33
63
kind : vscode . CompletionItemKind . Keyword ,
34
64
preselect : el . alias . includes ( search ) ,
35
65
documentation : new vscode . MarkdownString ( el . documentation . join ( '' ) ) ,
36
- insertText : el . insertText ? new vscode . SnippetString ( el . insertText ) : el . label
66
+ insertText : new vscode . SnippetString ( el . insertText || ` ${ el . label } $0` )
37
67
} ) ) ;
38
68
return {
39
69
isIncomplete : items . length > 0 ,
@@ -60,12 +90,9 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
60
90
if ( dollars === '$' ) {
61
91
let range = new vscode . Range (
62
92
new vscode . Position ( word . start . line , word . start . character - 1 ) ,
63
- new vscode . Position ( word . end . line , word . end . character + ( textAfter . startsWith ( '(' ) ? 1 : 0 ) )
93
+ new vscode . Position ( word . end . line , word . end . character )
64
94
) ;
65
- let items = [
66
- ...this . listSystemFunctions ( search , textAfter . startsWith ( '(' ) ) ,
67
- ...this . listSystemVariables ( search )
68
- ] ;
95
+ let items = [ ...this . listSystemFunctions ( search , textAfter . length > 0 ) , ...this . listSystemVariables ( search ) ] ;
69
96
return {
70
97
isIncomplete : items . length > 1 ,
71
98
items : items . map ( el => {
@@ -78,9 +105,9 @@ export class ObjectScriptCompletionItemProvider implements vscode.CompletionItem
78
105
} else if ( dollars === '^$' ) {
79
106
let range = new vscode . Range (
80
107
new vscode . Position ( word . start . line , word . start . character - 2 ) ,
81
- new vscode . Position ( word . end . line , word . end . character + ( textAfter . startsWith ( '(' ) ? 1 : 0 ) )
108
+ new vscode . Position ( word . end . line , word . end . character )
82
109
) ;
83
- return this . listStructuredSystemVariables ( search , textAfter . startsWith ( '(' ) ) . map ( el => {
110
+ return this . listStructuredSystemVariables ( search , textAfter . length > 0 ) . map ( el => {
84
111
return {
85
112
...el ,
86
113
range
0 commit comments