1
1
import { CancellationToken , CompletionContext , CompletionItem , CompletionItemKind , CompletionItemProvider , CompletionList , Position , ProviderResult , Range , TextDocument , window , workspace } from "vscode" ;
2
- import * as fs from "fs" ;
3
2
import { BackTrackSearchResult , DirectoryContent } from "../utils/interfaces" ;
4
3
import { setAutCompleteList } from "../utils/utils" ;
5
4
@@ -9,7 +8,7 @@ export class CompletionItems implements CompletionItemProvider {
9
8
// Condition for checkAndConfirm to work as expected
10
9
private isDirectoryChanged : boolean = false ;
11
10
12
- checkAndConfirm ( item : string ) {
11
+ private checkAndConfirm ( item : string ) {
13
12
if ( this . isDirectoryChanged )
14
13
return false ;
15
14
else {
@@ -20,7 +19,7 @@ export class CompletionItems implements CompletionItemProvider {
20
19
}
21
20
}
22
21
23
- backTrackAndCheckForString ( document : TextDocument , position : Position , testChar : string ) : BackTrackSearchResult {
22
+ private backTrackAndCheckForString ( document : TextDocument , position : Position , testChar : string ) : BackTrackSearchResult {
24
23
let i = 2 ;
25
24
if ( document . getText ( ) . split ( "\n" ) [ position . line ] . includes ( "$import " ) ) {
26
25
var positionCharacterMatch = document . getText ( new Range ( position , new Position ( position . line , position . character - i ) ) ) ;
@@ -34,22 +33,25 @@ export class CompletionItems implements CompletionItemProvider {
34
33
return {
35
34
strSet : positionCharacterMatch . substring ( 1 , positionCharacterMatch . length - 1 ) ,
36
35
result : true ,
37
- lastValidPath : lastValidPath . replace ( positionCharacterMatch , "" )
36
+ lastValidPath : lastValidPath . replace ( positionCharacterMatch , "" ) ,
37
+ fullImportStatement : lastValidPath
38
38
} ;
39
39
}
40
40
catch ( error ) {
41
41
return {
42
42
strSet : null ,
43
43
result : false ,
44
- lastValidPath : null
44
+ lastValidPath : null ,
45
+ fullImportStatement : lastValidPath
45
46
} ;
46
47
}
47
48
}
48
49
else {
49
50
return {
50
51
strSet : null ,
51
52
result : false ,
52
- lastValidPath : null
53
+ lastValidPath : null ,
54
+ fullImportStatement : null
53
55
}
54
56
}
55
57
}
@@ -66,20 +68,19 @@ export class CompletionItems implements CompletionItemProvider {
66
68
this . setCompletionItemsList ( ) ;
67
69
this . isDirectoryChanged = false ;
68
70
}
69
-
71
+ else if ( triggerToken === "." ) {
72
+ this . completionItemList = [ {
73
+ label : "/"
74
+ } ]
75
+ }
70
76
else if ( triggerToken === "/" || triggerToken === "\\" ) {
71
77
var backtrackResult : BackTrackSearchResult = this . backTrackAndCheckForString ( document , position , "." ) ;
72
78
this . isDirectoryChanged = true ;
73
79
74
80
if ( backtrackResult . result && backtrackResult . strSet !== null ) {
75
81
if ( this . fileList !== undefined ) {
76
82
this . fileList = setAutCompleteList ( backtrackResult . strSet ) ;
77
- //for(let i = 0; i < this.fileList.length; i ++) {
78
- // (this.fileList[i].filename === backtrackResult.strSet) &&
79
- //if(this.fileList[i].isDirectory) {
80
- this . setCompletionItemsList ( ) ;
81
- // }
82
- //}
83
+ this . setCompletionItemsList ( ) ;
83
84
}
84
85
else
85
86
this . completionItemList = [ ] ;
@@ -88,9 +89,17 @@ export class CompletionItems implements CompletionItemProvider {
88
89
else {
89
90
this . isDirectoryChanged = true ;
90
91
var backtrackResult : BackTrackSearchResult = this . backTrackAndCheckForString ( document , position , "/" ) ;
91
- this . fileList = setAutCompleteList ( "." ) ;
92
- this . setCompletionItemsList ( ) ;
93
- this . isDirectoryChanged = false ;
92
+ if ( backtrackResult . fullImportStatement !== null ) {
93
+ let importPaths : string [ ] = backtrackResult . fullImportStatement ?. split ( "/" ) ;
94
+ if ( importPaths [ importPaths . length - 1 ] . includes ( ".json" )
95
+ || importPaths [ importPaths . length - 1 ] . includes ( ".cjson" ) ) {
96
+ }
97
+ else {
98
+ this . fileList = setAutCompleteList ( "." ) ;
99
+ this . setCompletionItemsList ( ) ;
100
+ this . isDirectoryChanged = false ;
101
+ }
102
+ }
94
103
}
95
104
return this . completionItemList ;
96
105
}
@@ -99,10 +108,6 @@ export class CompletionItems implements CompletionItemProvider {
99
108
return item ;
100
109
}
101
110
102
- private getPreviousCompletePath ( ) {
103
-
104
- }
105
-
106
111
private setCompletionItemsList ( ) {
107
112
if ( this . fileList != undefined ) {
108
113
for ( let i = 0 ; i < this . fileList . length ; i ++ ) {
0 commit comments