Skip to content

Commit 9227fa8

Browse files
closes #175
1 parent 4234ae9 commit 9227fa8

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

cjson/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@
9191
"webpack-cli": "^5.1.4"
9292
},
9393
"dependencies": {
94-
"coded-json": "^2.1.0"
94+
"coded-json": "^2.1.1"
9595
}
9696
}

cjson/src/definitions/base.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Position, Range, TextDocument } from "vscode";
22

3-
export class Base {
3+
export abstract class Base {
44
protected getCharactersByRange(document: TextDocument, startPosition: Position, endPosition: Position) {
55
return document.getText(new Range(startPosition, endPosition));
66
}
7+
protected abstract checkAndConfirm(item: string): boolean;
78
}

cjson/src/definitions/completion-items.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ export class CompletionItems extends Base implements CompletionItemProvider {
1313
// Condition for checkAndConfirm to work as expected
1414
private isDirectoryChanged: boolean = false;
1515

16-
private checkAndConfirm(item: string) {
16+
protected checkAndConfirm(item: string): boolean {
1717
if(this.isDirectoryChanged)
1818
return false;
1919
else {
2020
for(let i = 0; i < this.completionItemList.length; i ++)
21-
if(JSON.parse(JSON.stringify(this.completionItemList[i].label.valueOf()))["label"] === item)
21+
if(JSON.parse(JSON.stringify(this.completionItemList[i].label.valueOf())) === item)
2222
return true;
2323
return false;
2424
}
@@ -157,15 +157,27 @@ export class CompletionItems extends Base implements CompletionItemProvider {
157157
export class RelativeVariableCompletionProvider extends Base implements CompletionItemProvider {
158158
public completionItemList: CompletionItem[] = [];
159159

160+
protected checkAndConfirm(item: string): boolean {
161+
for(let i = 0; i < this.completionItemList.length; i ++)
162+
if(JSON.parse(JSON.stringify(this.completionItemList[i].label.valueOf())) === item)
163+
return true;
164+
return false;
165+
}
166+
160167
provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken, context: CompletionContext): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
161-
let matchChars = this.getCharactersByRange(document, position, new Position(position.line, position.character - 1));
162168
if(workspace.workspaceFolders) {
163-
var a = document.fileName;
164-
if(a !== undefined) {
165-
var cjson = new Cjson(a);
166-
cjson.json?.getAllKeys().map(eachElem => this.completionItemList.push(new CompletionItem(eachElem)));
169+
if(document.fileName !== undefined) {
170+
var cjson = new Cjson(document.fileName);
171+
cjson.json?.getAllKeys().map((eachElem) => {
172+
if(! this.checkAndConfirm(eachElem))
173+
this.completionItemList.push(new CompletionItem(eachElem));
174+
});
167175
}
176+
else
177+
window.showErrorMessage("No CJSON file is opened");
168178
}
179+
else
180+
window.showErrorMessage("CJSON requires folder to be opened");
169181
return this.completionItemList;
170182
}
171183
resolveCompletionItem?(item: CompletionItem, token: CancellationToken): ProviderResult<CompletionItem> {

0 commit comments

Comments
 (0)