[mod] ver:0.0.28
This commit is contained in:
parent
560628c7de
commit
9dd58b2b70
21 changed files with 1129 additions and 1253 deletions
8
src/@quodatum/xqlint.d.ts
vendored
Normal file
8
src/@quodatum/xqlint.d.ts
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
declare module '@quodatum/xqlint'{
|
||||
export function XQLint(source :string, opts :object) :any;
|
||||
export function XQueryLexer() :any;
|
||||
export function createStaticContext(processor :string) :any;
|
||||
export function CodeFormatter(ast :object) :any;
|
||||
export function CodeFormatter(ast :object, newLinesEnabled :boolean, DEBUG :any) :any;
|
||||
|
||||
}
|
||||
|
|
@ -3,3 +3,4 @@ export * from "./create-document-selector";
|
|||
export * from "./extension-state";
|
||||
export * from "./native-commands";
|
||||
export * from "./xml-traverser";
|
||||
export * from "./logger";
|
||||
|
|
|
|||
23
src/common/logger.ts
Normal file
23
src/common/logger.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// debug messages
|
||||
import { OutputChannel, window } from "vscode";
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const XQLint = require("@quodatum/xqlint").XQLint;
|
||||
|
||||
const _channel:OutputChannel = window.createOutputChannel("BaseX log");
|
||||
function logdate(){
|
||||
return (new Date()).toISOString().slice(0, 19).replace(/-/g, "/").replace("T", " ");
|
||||
}
|
||||
|
||||
export class channel {
|
||||
static log(msg: string) :void{
|
||||
_channel.appendLine("["+logdate()+"] "+msg)
|
||||
}
|
||||
static appendLine(msg: string) :void{
|
||||
_channel.appendLine(msg)
|
||||
}
|
||||
static show() :void{
|
||||
_channel.show
|
||||
}
|
||||
}
|
||||
channel.log("started, XQLint version: "+XQLint.version);
|
||||
_channel.show
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { CompletionItem, CompletionItemKind, CompletionItemProvider, Position, TextDocument } from "vscode";
|
||||
|
||||
const XQLint = require("xqlint").XQLint;
|
||||
const XQLint = require("@quodatum/xqlint").XQLint;
|
||||
|
||||
export class XQueryCompletionItemProvider implements CompletionItemProvider {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import {
|
||||
commands, languages, window, workspace, ExtensionContext, Memento,
|
||||
TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind, DiagnosticCollection
|
||||
TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind, DiagnosticCollection, TextDocument, TextEdit,Range
|
||||
} from "vscode";
|
||||
import { channel } from "./common/logger";
|
||||
|
||||
import { createDocumentSelector, ExtensionState, Configuration } from "./common";
|
||||
import { XQueryCompletionItemProvider } from "./completion";
|
||||
|
|
@ -13,10 +14,12 @@ import { evaluateXPath, getCurrentXPath } from "./xpath/commands";
|
|||
import { executeXQuery } from "./xquery-execution/commands";
|
||||
|
||||
import * as constants from "./constants";
|
||||
import { XQueryFormatter } from "./formatting/XQueryFormatter";
|
||||
|
||||
let diagnosticCollectionXQuery: DiagnosticCollection;
|
||||
|
||||
export function activate(context: ExtensionContext) {
|
||||
channel.log("Extension activate");
|
||||
ExtensionState.configure(context);
|
||||
|
||||
const xmlXsdDocSelector = [...createDocumentSelector(constants.languageIds.xml), ...createDocumentSelector(constants.languageIds.xsd)];
|
||||
|
|
@ -39,6 +42,20 @@ export function activate(context: ExtensionContext) {
|
|||
languages.registerDocumentRangeFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider)
|
||||
);
|
||||
|
||||
// 👍 XQuery formatter implemented using API
|
||||
languages.registerDocumentFormattingEditProvider(constants.languageIds.xquery, {
|
||||
async provideDocumentFormattingEdits(document: TextDocument): Promise<TextEdit[]> {
|
||||
|
||||
try {
|
||||
const text = XQueryFormatter.format(document.getText())
|
||||
const entireDocRange = document.validateRange(new Range(0, 0, document.lineCount, 0));
|
||||
return [TextEdit.replace(entireDocRange, text)];
|
||||
} catch (e) {
|
||||
window.showInformationMessage('Format failed -syntax error')
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* Linting Features */
|
||||
diagnosticCollectionXQuery = languages.createDiagnosticCollection(constants.diagnosticCollections.xquery);
|
||||
context.subscriptions.push(
|
||||
|
|
@ -75,12 +92,12 @@ export function activate(context: ExtensionContext) {
|
|||
context.subscriptions.push(
|
||||
commands.registerTextEditorCommand(constants.commands.executeXQuery, executeXQuery)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function _handleContextChange(editor: TextEditor): void {
|
||||
const supportedSchemes = [constants.uriSchemes.file, constants.uriSchemes.untitled];
|
||||
|
|
|
|||
18
src/formatting/XQueryFormatter.ts
Normal file
18
src/formatting/XQueryFormatter.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// format xquery
|
||||
import { channel } from "../common/logger";
|
||||
import { XQLint, CodeFormatter } from "@quodatum/xqlint";
|
||||
|
||||
|
||||
export class XQueryFormatter {
|
||||
static format(xquery: string): string {
|
||||
channel.log("XQueryFormatter");
|
||||
const linter = new (XQLint as any)(xquery, { "styleCheck": false });
|
||||
channel.appendLine("got linter: " + linter.hasSyntaxError());
|
||||
//if(linter.hasSyntaxError()+linter.hasSyntaxError()) throw new Error("XQuery syntax error")
|
||||
const ast = linter.getAST()
|
||||
const formatter = new (CodeFormatter as any)(ast);
|
||||
const formatted = formatter.format().trim();
|
||||
channel.log("XQueryFormatter done");
|
||||
return formatted;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,9 @@
|
|||
import { workspace } from "vscode";
|
||||
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
|
||||
|
||||
import { NativeCommands } from "../../common";
|
||||
import * as constants from "../../constants";
|
||||
|
||||
import { XmlFormatterFactory } from "../xml-formatter";
|
||||
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
|
||||
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
|
||||
|
||||
export function formatAsXml(editor: TextEditor, edit: TextEditorEdit): void {
|
||||
const xmlFormattingEditProvider = new XmlFormattingEditProvider(XmlFormatterFactory.getXmlFormatter());
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Diagnostic, DiagnosticSeverity, Position, Range } from "vscode";
|
||||
|
||||
const XQLint = require("xqlint").XQLint;
|
||||
const XQLint = require("@quodatum/xqlint").XQLint;
|
||||
|
||||
export class XQueryLinter {
|
||||
static SEVERITY_WARNING = 1;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import {
|
|||
} from "vscode";
|
||||
|
||||
import * as path from "path";
|
||||
import { DOMParser } from "xmldom";
|
||||
import { DOMParser } from "@xmldom/xmldom";
|
||||
|
||||
import { Configuration, NativeCommands, XmlTraverser } from "../common";
|
||||
import * as constants from "../constants";
|
||||
|
|
@ -15,6 +15,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
|
|||
private _xmlDocument: Document;
|
||||
private _xmlTraverser: XmlTraverser;
|
||||
|
||||
|
||||
constructor(private _context: ExtensionContext) {
|
||||
window.onDidChangeActiveTextEditor(() => {
|
||||
this._refreshTree();
|
||||
|
|
@ -134,7 +135,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
|
|||
NativeCommands.setContext(constants.contextKeys.xmlTreeViewEnabled, false);
|
||||
|
||||
this._xmlDocument = null;
|
||||
this._onDidChangeTreeData.fire(0);
|
||||
this._onDidChangeTreeData.fire(null);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +163,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
|
|||
this._xmlTraverser.xmlDocument = this._xmlDocument;
|
||||
}
|
||||
|
||||
this._onDidChangeTreeData.fire(0);
|
||||
this._onDidChangeTreeData.fire(this.activeEditor.document.uri);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { window } from "vscode";
|
||||
import { TextEditor, TextEditorEdit } from "vscode";
|
||||
import { DOMParser } from "xmldom";
|
||||
import { DOMParser } from "@xmldom/xmldom";
|
||||
|
||||
import { XPathBuilder } from "../xpath-builder";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as xpath from "xpath";
|
||||
import { SelectedValue, XPathSelect } from "xpath";
|
||||
import { DOMParser } from "xmldom";
|
||||
import { DOMParser } from "@xmldom/xmldom";
|
||||
|
||||
export class EvaluatorResult {
|
||||
type: EvaluatorResultType;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue