[mod] ver:0.0.28

This commit is contained in:
Andy Bunce 2022-02-20 18:57:48 +00:00
parent 560628c7de
commit 9dd58b2b70
21 changed files with 1129 additions and 1253 deletions

20
.eslintrc.json Normal file
View file

@ -0,0 +1,20 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ out
node_modules node_modules
.vscode-test/ .vscode-test/
/*.vsix /*.vsix

3
.vscode/launch.json vendored
View file

@ -2,13 +2,14 @@
{ {
"version": "0.1.0", "version": "0.1.0",
"configurations": [ "configurations": [
{ {
"name": "Extension", "name": "Extension",
"type": "extensionHost", "type": "extensionHost",
"request": "launch", "request": "launch",
"runtimeExecutable": "${execPath}", "runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ], "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false, "stopOnEntry": true,
"sourceMaps": true, "sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/**/*.js" ], "outFiles": [ "${workspaceRoot}/out/**/*.js" ],
"preLaunchTask": "npm: watch" "preLaunchTask": "npm: watch"

View file

@ -1,5 +1,7 @@
node_modules
out/
src/ src/
tsconfig.json tsconfig.json
vsc-extension-quickstart.md vsc-extension-quickstart.md
.github
.gitignore
.vscode

View file

@ -1,3 +1,4 @@
Detailed release notes are available [here](https://github.com/DotJoshJohnson/vscode-xml/releases). Detailed release notes are available [here](https://github.com/DotJoshJohnson/vscode-xml/releases).
0.0.27 doc format
0.0.4 [add] treat schematron (.sch) as XML 0.0.4 [add] treat schematron (.sch) as XML

View file

@ -1,6 +1,9 @@
# BaseX Tools for Visual Studio Code # BaseX Tools for Visual Studio Code
This project was originally a fork of https://github.com/DotJoshJohnson/vscode-xml This project was originally a fork of https://github.com/DotJoshJohnson/vscode-xml
This extension adds features to support BaseX development on VSCode.
* XQuery 3.1, XQuery update, Full text syntax support
* XQuery code format
## Features ## Features
* [XML Formatting](https://github.com/DotJoshJohnson/vscode-xml/wiki/xml-formatting) * [XML Formatting](https://github.com/DotJoshJohnson/vscode-xml/wiki/xml-formatting)
@ -11,21 +14,7 @@ This project was originally a fork of https://github.com/DotJoshJohnson/vscode-x
* [XQuery Code Completion](https://github.com/DotJoshJohnson/vscode-xml/wiki/xquery-code-completion) * [XQuery Code Completion](https://github.com/DotJoshJohnson/vscode-xml/wiki/xquery-code-completion)
## Requirements ## Requirements
* VS Code `1.22.2` or higher * VS Code `1.63.0` or higher
## Extension Settings
* **`basexTools.enableXmlTreeView`:** Enables the XML Tree View for XML documents.
* **`basexTools.enableXmlTreeViewMetadata`:** Enables attribute and child element counts in the XML Document view.
* **`basexTools.enableXmlTreeViewCursorSync`:** Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.
* **`basexTools.enforcePrettySelfClosingTagOnFormat`:** Ensures a space is added before the forward slash at the end of a self-closing tag.
* **`basexTools.ignoreDefaultNamespace`:** Ignore default xmlns attributes when evaluating XPath.
* **`basexTools.persistXPathQuery`:** Remember the last XPath query used.
* **`basexTools.removeCommentsOnMinify`:** Remove XML comments during minification.
* **`basexTools.splitAttributesOnFormat`:** Put each attribute on a new line when formatting XML. Overrides `basexTools.splitXmlnsOnFormat` if set to `true`. (V2 Formatter Only)
* **`basexTools.splitXmlnsOnFormat`:** Put each xmlns attribute on a new line when formatting XML.
* **`basexTools.xmlFormatterImplementation`:** Supported XML Formatters: `classic`, `v2`.
* **`basexTools.xqueryExecutionArguments`:** Arguments to be passed to the XQuery execution engine.
* **`basexTools.xqueryExecutionEngine`:** The full path to the executable to run when executing XQuery scripts.
## Release Notes ## Release Notes
Detailed release notes are available [here](https://github.com/DotJoshJohnson/vscode-xml/releases). Detailed release notes are available [here](https://github.com/DotJoshJohnson/vscode-xml/releases).
@ -37,3 +26,7 @@ Run into a bug? Report it [here](https://github.com/DotJoshJohnson/vscode-xml/is
Icons used in the XML Tree View are used under the Creative Commons 3.0 BY license. Icons used in the XML Tree View are used under the Creative Commons 3.0 BY license.
* "Code" icon by Dave Gandy from www.flaticon.com * "Code" icon by Dave Gandy from www.flaticon.com
* "At" icon by FreePik from www.flaticon.com * "At" icon by FreePik from www.flaticon.com
## Inspiration
This is a fork of [DotJoshJohnson/vscode-xml](https://github.com/DotJoshJohnson/vscode-xml). DotJoshJohnson did the intial work, but I want to go in a different direction.

57
notes.md Normal file
View file

@ -0,0 +1,57 @@
# Debugging 2022-02-12...
## apb.js
```javascript
var XQLint = require('../lib/xqlint').XQLint;
var source = 'let $v1 := 1\nlet $foo := $v1\nreturn $v1 + $';
var linter = new XQLint(source);
var lines = source.split('\n');
var pos = { line: lines.length -1 , col: lines[lines.length - 1].length };
var proposals = linter.getCompletions(pos);
console.log(proposals);
```
------
## completer.js/getCompletions
### wcandillon /xqlint
```javascript
ast.pos={sl: 0, sc: 0, el: 2, ec: 14}
pos={col:14,line:2}
node=TreeOps.findNode(ast, pos);
// node{name: 'token', value: "$"}
sctx = TreeOps.findNode(rootSctx, pos);
```
### quodatum
```javascript
pos={col:14,line:2}
ast.pos={sl: 0, sc: 0, el: 2, ec: **10**}
ast.name=XQuery
```
Therefore error is in XQlint
## XQLint
```javascript
// save source, ast=null
var h = new JSONParseTreeHandler(source);
// set source and handler
var parser = new XQueryParser(source, h);
try {
// attempt to parse startNonterminal "XQuery"
parser.parse_XQuery();
}catch(e){
syntaxError = true;
h.closeParseTree();
}
ast = h.getParseTree();
```
### wcandillon /xqlint
```javascript
ast.pos={sl: 0, sc: 0, el: 2, ec: 14}
```
### quodatum
```javascript
pos={col:14,line:2}
```

1594
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -2,13 +2,10 @@
"name": "vscode-basex", "name": "vscode-basex",
"displayName": "BaseX tools", "displayName": "BaseX tools",
"description": "BaseX tools: XQuery, XML, XPath Tools for Visual Studio Code", "description": "BaseX tools: XQuery, XML, XPath Tools for Visual Studio Code",
"version": "0.0.6", "version": "0.0.28",
"preview": false, "preview": true,
"publisher": "quodatum", "publisher": "quodatum",
"author": { "author": "Andy Bunce (https://github.com/Quodatum)",
"name": "Andy Bunce",
"url": "https://github.com/Quodatum"
},
"license": "MIT", "license": "MIT",
"galleryBanner": { "galleryBanner": {
"color": "#FFFFFF", "color": "#FFFFFF",
@ -18,7 +15,7 @@
"homepage": "https://github.com/Quodatum/vscode-xml", "homepage": "https://github.com/Quodatum/vscode-xml",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/Quodatum/vscode-xml.git" "url": "git+https://github.com/Quodatum/vscode-xml.git"
}, },
"bugs": { "bugs": {
"url": "https://github.com/Quodatum/vscode-xml/issues" "url": "https://github.com/Quodatum/vscode-xml/issues"
@ -76,7 +73,7 @@
} }
], ],
"configuration": { "configuration": {
"title": "XML Tools Configuration", "title": "BaseX Tools Configuration",
"type": "object", "type": "object",
"properties": { "properties": {
"basexTools.enableXmlTreeView": { "basexTools.enableXmlTreeView": {
@ -262,7 +259,7 @@
}, },
"scripts": { "scripts": {
"vscode:prepublish": "npm run esbuild-base -- --minify", "vscode:prepublish": "npm run esbuild-base -- --minify",
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node", "esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node",
"esbuild": "npm run esbuild-base -- --sourcemap", "esbuild": "npm run esbuild-base -- --sourcemap",
"esbuild-watch": "npm run esbuild-base -- --sourcemap --watch", "esbuild-watch": "npm run esbuild-base -- --sourcemap --watch",
"test-compile": "tsc -p ./", "test-compile": "tsc -p ./",
@ -275,21 +272,21 @@
"devDependencies": { "devDependencies": {
"@types/glob": "^7.2.0", "@types/glob": "^7.2.0",
"@types/mocha": "^9.0.0", "@types/mocha": "^9.0.0",
"@types/node": "14.x", "@types/node": "^14.18.12",
"@types/vscode": "^1.63.0", "@types/vscode": "^1.63.0",
"@types/xmldom": "^0.1.13", "@types/xmldom": "^0.1.31",
"@typescript-eslint/eslint-plugin": "^5.9.1", "@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.9.1", "@typescript-eslint/parser": "^5.12.0",
"@vscode/test-electron": "^2.0.3", "@vscode/test-electron": "^2.1.2",
"esbuild": "^0.14.18", "esbuild": "^0.14.23",
"eslint": "^8.6.0", "eslint": "^8.9.0",
"glob": "^7.2.0", "glob": "^7.2.0",
"mocha": "^9.1.3", "mocha": "^9.2.1",
"typescript": "^4.5.4" "typescript": "^4.5.4"
}, },
"dependencies": { "dependencies": {
"xmldom": "^0.1.27", "@quodatum/xqlint": "^0.0.8",
"xpath": "0.0.27", "@xmldom/xmldom": "^0.8.1",
"xqlint": "^0.4.1" "xpath": "0.0.32"
} }
} }

13
scripts/test.js Normal file
View file

@ -0,0 +1,13 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const XQLint =require("@quodatum/xqlint").XQLint;
const CodeFormatter=require( "@quodatum/xqlint").CodeFormatter;
console.log("....");
const xquery="2 +4 ";
const linter = new XQLint(xquery, { "styleCheck": false }) ;
//if(linter.hasSyntaxError()+linter.hasSyntaxError()) throw new Error("XQuery syntax error")
const ast=linter.getAST()
const formatter = new CodeFormatter(ast);
const formatted = formatter.format().trim();
console.log(formatted);

8
src/@quodatum/xqlint.d.ts vendored Normal file
View 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;
}

View file

@ -3,3 +3,4 @@ export * from "./create-document-selector";
export * from "./extension-state"; export * from "./extension-state";
export * from "./native-commands"; export * from "./native-commands";
export * from "./xml-traverser"; export * from "./xml-traverser";
export * from "./logger";

23
src/common/logger.ts Normal file
View 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

View file

@ -1,6 +1,6 @@
import { CompletionItem, CompletionItemKind, CompletionItemProvider, Position, TextDocument } from "vscode"; import { CompletionItem, CompletionItemKind, CompletionItemProvider, Position, TextDocument } from "vscode";
const XQLint = require("xqlint").XQLint; const XQLint = require("@quodatum/xqlint").XQLint;
export class XQueryCompletionItemProvider implements CompletionItemProvider { export class XQueryCompletionItemProvider implements CompletionItemProvider {

View file

@ -1,7 +1,8 @@
import { import {
commands, languages, window, workspace, ExtensionContext, Memento, commands, languages, window, workspace, ExtensionContext, Memento,
TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind, DiagnosticCollection TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind, DiagnosticCollection, TextDocument, TextEdit,Range
} from "vscode"; } from "vscode";
import { channel } from "./common/logger";
import { createDocumentSelector, ExtensionState, Configuration } from "./common"; import { createDocumentSelector, ExtensionState, Configuration } from "./common";
import { XQueryCompletionItemProvider } from "./completion"; import { XQueryCompletionItemProvider } from "./completion";
@ -13,10 +14,12 @@ import { evaluateXPath, getCurrentXPath } from "./xpath/commands";
import { executeXQuery } from "./xquery-execution/commands"; import { executeXQuery } from "./xquery-execution/commands";
import * as constants from "./constants"; import * as constants from "./constants";
import { XQueryFormatter } from "./formatting/XQueryFormatter";
let diagnosticCollectionXQuery: DiagnosticCollection; let diagnosticCollectionXQuery: DiagnosticCollection;
export function activate(context: ExtensionContext) { export function activate(context: ExtensionContext) {
channel.log("Extension activate");
ExtensionState.configure(context); ExtensionState.configure(context);
const xmlXsdDocSelector = [...createDocumentSelector(constants.languageIds.xml), ...createDocumentSelector(constants.languageIds.xsd)]; const xmlXsdDocSelector = [...createDocumentSelector(constants.languageIds.xml), ...createDocumentSelector(constants.languageIds.xsd)];
@ -39,6 +42,20 @@ export function activate(context: ExtensionContext) {
languages.registerDocumentRangeFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider) 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 */ /* Linting Features */
diagnosticCollectionXQuery = languages.createDiagnosticCollection(constants.diagnosticCollections.xquery); diagnosticCollectionXQuery = languages.createDiagnosticCollection(constants.diagnosticCollections.xquery);
context.subscriptions.push( context.subscriptions.push(
@ -75,12 +92,12 @@ export function activate(context: ExtensionContext) {
context.subscriptions.push( context.subscriptions.push(
commands.registerTextEditorCommand(constants.commands.executeXQuery, executeXQuery) commands.registerTextEditorCommand(constants.commands.executeXQuery, executeXQuery)
); );
} }
export function deactivate() { export function deactivate() {
// do nothing // do nothing
} };
function _handleContextChange(editor: TextEditor): void { function _handleContextChange(editor: TextEditor): void {
const supportedSchemes = [constants.uriSchemes.file, constants.uriSchemes.untitled]; const supportedSchemes = [constants.uriSchemes.file, constants.uriSchemes.untitled];

View 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;
}
}

View file

@ -1,12 +1,9 @@
import { workspace } from "vscode";
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode"; import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
import { NativeCommands } from "../../common"; import { NativeCommands } from "../../common";
import * as constants from "../../constants";
import { XmlFormatterFactory } from "../xml-formatter"; import { XmlFormatterFactory } from "../xml-formatter";
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider"; import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
export function formatAsXml(editor: TextEditor, edit: TextEditorEdit): void { export function formatAsXml(editor: TextEditor, edit: TextEditorEdit): void {
const xmlFormattingEditProvider = new XmlFormattingEditProvider(XmlFormatterFactory.getXmlFormatter()); const xmlFormattingEditProvider = new XmlFormattingEditProvider(XmlFormatterFactory.getXmlFormatter());

View file

@ -1,6 +1,6 @@
import { Diagnostic, DiagnosticSeverity, Position, Range } from "vscode"; import { Diagnostic, DiagnosticSeverity, Position, Range } from "vscode";
const XQLint = require("xqlint").XQLint; const XQLint = require("@quodatum/xqlint").XQLint;
export class XQueryLinter { export class XQueryLinter {
static SEVERITY_WARNING = 1; static SEVERITY_WARNING = 1;

View file

@ -5,7 +5,7 @@ import {
} from "vscode"; } from "vscode";
import * as path from "path"; import * as path from "path";
import { DOMParser } from "xmldom"; import { DOMParser } from "@xmldom/xmldom";
import { Configuration, NativeCommands, XmlTraverser } from "../common"; import { Configuration, NativeCommands, XmlTraverser } from "../common";
import * as constants from "../constants"; import * as constants from "../constants";
@ -15,6 +15,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
private _xmlDocument: Document; private _xmlDocument: Document;
private _xmlTraverser: XmlTraverser; private _xmlTraverser: XmlTraverser;
constructor(private _context: ExtensionContext) { constructor(private _context: ExtensionContext) {
window.onDidChangeActiveTextEditor(() => { window.onDidChangeActiveTextEditor(() => {
this._refreshTree(); this._refreshTree();
@ -134,7 +135,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
NativeCommands.setContext(constants.contextKeys.xmlTreeViewEnabled, false); NativeCommands.setContext(constants.contextKeys.xmlTreeViewEnabled, false);
this._xmlDocument = null; this._xmlDocument = null;
this._onDidChangeTreeData.fire(0); this._onDidChangeTreeData.fire(null);
return; return;
} }
@ -162,7 +163,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
this._xmlTraverser.xmlDocument = this._xmlDocument; this._xmlTraverser.xmlDocument = this._xmlDocument;
} }
this._onDidChangeTreeData.fire(0); this._onDidChangeTreeData.fire(this.activeEditor.document.uri);
} }
} }

View file

@ -1,6 +1,6 @@
import { window } from "vscode"; import { window } from "vscode";
import { TextEditor, TextEditorEdit } from "vscode"; import { TextEditor, TextEditorEdit } from "vscode";
import { DOMParser } from "xmldom"; import { DOMParser } from "@xmldom/xmldom";
import { XPathBuilder } from "../xpath-builder"; import { XPathBuilder } from "../xpath-builder";

View file

@ -1,6 +1,6 @@
import * as xpath from "xpath"; import * as xpath from "xpath";
import { SelectedValue, XPathSelect } from "xpath"; import { SelectedValue, XPathSelect } from "xpath";
import { DOMParser } from "xmldom"; import { DOMParser } from "@xmldom/xmldom";
export class EvaluatorResult { export class EvaluatorResult {
type: EvaluatorResultType; type: EvaluatorResultType;