Skip to content

Commit f10cbb3

Browse files
closes #155 #159
1 parent 4e538f8 commit f10cbb3

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

cjson/src/auto_completes/completion-items.ts

+25-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { CancellationToken, CompletionContext, CompletionItem, CompletionItemKind, CompletionItemProvider, CompletionList, Position, ProviderResult, Range, TextDocument, window, workspace } from "vscode";
2-
import * as fs from "fs";
32
import { BackTrackSearchResult, DirectoryContent } from "../utils/interfaces";
43
import { setAutCompleteList } from "../utils/utils";
54

@@ -9,7 +8,7 @@ export class CompletionItems implements CompletionItemProvider {
98
// Condition for checkAndConfirm to work as expected
109
private isDirectoryChanged: boolean = false;
1110

12-
checkAndConfirm(item: string) {
11+
private checkAndConfirm(item: string) {
1312
if(this.isDirectoryChanged)
1413
return false;
1514
else {
@@ -20,7 +19,7 @@ export class CompletionItems implements CompletionItemProvider {
2019
}
2120
}
2221

23-
backTrackAndCheckForString(document: TextDocument, position: Position, testChar: string): BackTrackSearchResult {
22+
private backTrackAndCheckForString(document: TextDocument, position: Position, testChar: string): BackTrackSearchResult {
2423
let i = 2;
2524
if(document.getText().split("\n")[position.line].includes("$import ")) {
2625
var positionCharacterMatch = document.getText(new Range(position, new Position(position.line, position.character - i)));
@@ -34,22 +33,25 @@ export class CompletionItems implements CompletionItemProvider {
3433
return {
3534
strSet: positionCharacterMatch.substring(1, positionCharacterMatch.length - 1),
3635
result: true,
37-
lastValidPath: lastValidPath.replace(positionCharacterMatch, "")
36+
lastValidPath: lastValidPath.replace(positionCharacterMatch, ""),
37+
fullImportStatement: lastValidPath
3838
};
3939
}
4040
catch(error) {
4141
return {
4242
strSet: null,
4343
result: false,
44-
lastValidPath: null
44+
lastValidPath: null,
45+
fullImportStatement: lastValidPath
4546
};
4647
}
4748
}
4849
else {
4950
return {
5051
strSet: null,
5152
result: false,
52-
lastValidPath: null
53+
lastValidPath: null,
54+
fullImportStatement: null
5355
}
5456
}
5557
}
@@ -66,20 +68,19 @@ export class CompletionItems implements CompletionItemProvider {
6668
this.setCompletionItemsList();
6769
this.isDirectoryChanged = false;
6870
}
69-
71+
else if(triggerToken === ".") {
72+
this.completionItemList = [{
73+
label: "/"
74+
}]
75+
}
7076
else if(triggerToken === "/" || triggerToken === "\\") {
7177
var backtrackResult: BackTrackSearchResult = this.backTrackAndCheckForString(document, position, ".");
7278
this.isDirectoryChanged = true;
7379

7480
if(backtrackResult.result && backtrackResult.strSet !== null) {
7581
if(this.fileList !== undefined) {
7682
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();
8384
}
8485
else
8586
this.completionItemList = [];
@@ -88,9 +89,17 @@ export class CompletionItems implements CompletionItemProvider {
8889
else {
8990
this.isDirectoryChanged = true;
9091
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+
}
94103
}
95104
return this.completionItemList;
96105
}
@@ -99,10 +108,6 @@ export class CompletionItems implements CompletionItemProvider {
99108
return item;
100109
}
101110

102-
private getPreviousCompletePath() {
103-
104-
}
105-
106111
private setCompletionItemsList() {
107112
if(this.fileList != undefined) {
108113
for(let i = 0; i < this.fileList.length; i ++) {

cjson/src/utils/interfaces.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export interface DirectoryContent {
77
export interface BackTrackSearchResult {
88
strSet: string | null,
99
result: boolean,
10-
lastValidPath: string | null
10+
lastValidPath: string | null,
11+
fullImportStatement: string | null
1112
}

0 commit comments

Comments
 (0)