forked from external/vscode-xml
Port vscode-xquery to vscode-xml
I'll be consolidating the two extensions into one.
This commit is contained in:
parent
b259f68d72
commit
8738058d8c
8 changed files with 1290 additions and 4 deletions
43
src/services/XQueryCompleter.ts
Normal file
43
src/services/XQueryCompleter.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
'use strict';
|
||||
|
||||
let XQLint = require('xqlint').XQLint;
|
||||
|
||||
export class XQueryCompleter {
|
||||
constructor(script: string) {
|
||||
this.script = script;
|
||||
}
|
||||
|
||||
private _script: string;
|
||||
private _linter: any;
|
||||
|
||||
get script(): string {
|
||||
return this._script;
|
||||
}
|
||||
|
||||
set script(value: string) {
|
||||
this._script = value;
|
||||
this._linter = new XQLint(this._script);
|
||||
}
|
||||
|
||||
getCompletions(line: number, column: number): XQueryCompletionItem[] {
|
||||
let items: XQueryCompletionItem[] = new Array<XQueryCompletionItem>();
|
||||
|
||||
this._linter.getCompletions({line: line, col: column}).forEach((completion: any) => {
|
||||
items.push(new XQueryCompletionItem(completion.name, completion.value, completion.meta));
|
||||
});
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
export class XQueryCompletionItem {
|
||||
constructor(name: string, value: string, meta: string) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
name: string;
|
||||
value: string;
|
||||
meta: string;
|
||||
}
|
||||
41
src/services/XQueryLinter.ts
Normal file
41
src/services/XQueryLinter.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
'use strict';
|
||||
|
||||
let XQLint = require('xqlint').XQLint;
|
||||
|
||||
export class XQueryLinter {
|
||||
static SEVERITY_WARNING: number = 1;
|
||||
static SEVERITY_ERROR: number = 2;
|
||||
|
||||
static lint(text: string): XQueryDiagnostic[] {
|
||||
let linter = new XQLint(text);
|
||||
let diagnostics: XQueryDiagnostic[] = new Array<XQueryDiagnostic>();
|
||||
|
||||
linter.getErrors().forEach((error: any) => {
|
||||
diagnostics.push(new XQueryDiagnostic(XQueryLinter.SEVERITY_ERROR, error.message, error.pos.sl, error.pos.sc, error.pos.el, error.pos.ec));
|
||||
});
|
||||
|
||||
linter.getWarnings().forEach((warning: any) => {
|
||||
diagnostics.push(new XQueryDiagnostic(XQueryLinter.SEVERITY_WARNING, warning.message, warning.pos.sl, warning.pos.sc, warning.pos.el, warning.pos.ec));
|
||||
});
|
||||
|
||||
return diagnostics;
|
||||
}
|
||||
}
|
||||
|
||||
export class XQueryDiagnostic {
|
||||
constructor(severity: number, message: string, startLine: number, startColumn: number, endLine: number, endColumn: number) {
|
||||
this.severity = severity;
|
||||
this.message = message;
|
||||
this.startLine = startLine;
|
||||
this.startColumn = startColumn;
|
||||
this.endLine = endLine;
|
||||
this.endColumn = endColumn;
|
||||
}
|
||||
|
||||
severity: number;
|
||||
message: string;
|
||||
startLine: number;
|
||||
startColumn: number;
|
||||
endLine: number;
|
||||
endColumn: number;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue