vscode-basex #9

Merged
apb merged 5 commits from vscode-basex into master 2022-06-07 17:44:26 +01:00
6 changed files with 164 additions and 158 deletions
Showing only changes of commit cfc8ba3817 - Show all commits

View file

@ -2,7 +2,7 @@
"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.47", "version": "0.0.48",
"preview": true, "preview": true,
"publisher": "quodatum", "publisher": "quodatum",
"author": "Andy Bunce (https://github.com/Quodatum)", "author": "Andy Bunce (https://github.com/Quodatum)",
@ -72,107 +72,122 @@
"title": "BaseX Tools: Minify XML" "title": "BaseX Tools: Minify XML"
} }
], ],
"configuration": { "configuration": [
"title": "BaseX Tools Configuration", {
"type": "object", "id": "xmltree",
"properties": { "title": "XML tree view ",
"basexTools.xmlTree.enableTreeView": { "properties": {
"type": "boolean", "basexTools.xmlTree.enableTreeView": {
"default": true, "type": "boolean",
"description": "Enables the XML Document view in the explorer for XML documents.", "default": true,
"scope": "window" "description": "Enables the XML Document view in the explorer for XML documents.",
}, "scope": "window"
"basexTools.xmlTree.enableViewMetadata": { },
"type": "boolean", "basexTools.xmlTree.enableViewMetadata": {
"default": true, "type": "boolean",
"description": "Enables attribute and child element counts in the XML Document view.", "default": true,
"scope": "window" "description": "Enables attribute and child element counts in the XML Document view.",
}, "scope": "window"
"basexTools.xmlTree.enableViewCursorSync": { },
"type": "boolean", "basexTools.xmlTree.enableViewCursorSync": {
"default": false, "type": "boolean",
"description": "Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.", "default": false,
"scope": "window" "description": "Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.",
}, "scope": "window"
"basexTools.enforcePrettySelfClosingTagOnFormat": { }
"type": "boolean", }
"default": false, },
"description": "Enforces a space before the forward slash at the end of a self-closing XML tag.", {
"scope": "resource" "id": "xpath",
}, "title": "XPath ",
"basexTools.xpath.ignoreDefaultNamespace": { "properties":{
"type": "boolean", "basexTools.xpath.ignoreDefaultNamespace": {
"default": true, "type": "boolean",
"description": "Ignore default xmlns attributes when evaluating XPath.", "default": true,
"scope": "window" "description": "Ignore default xmlns attributes when evaluating XPath.",
}, "scope": "window"
"basexTools.xpath.persistXPathQuery": { },
"type": "boolean", "basexTools.xpath.persistXPathQuery": {
"default": true, "type": "boolean",
"description": "Remember the last XPath query used.", "default": true,
"scope": "window" "description": "Remember the last XPath query used.",
}, "scope": "window"
"basexTools.removeCommentsOnMinify": { }
"type": "boolean", }
"default": false, },
"description": "Remove XML comments during minification.", {
"scope": "resource" "title": "BaseX Tools ",
}, "type": "object",
"basexTools.splitAttributesOnFormat": { "properties": {
"type": "boolean", "basexTools.enforcePrettySelfClosingTagOnFormat": {
"default": false, "type": "boolean",
"description": "Put each attribute on a new line when formatting XML. Overrides `basexTools.splitXmlnsOnFormat` if set to `true`.", "default": false,
"scope": "resource" "description": "Enforces a space before the forward slash at the end of a self-closing XML tag.",
}, "scope": "resource"
"basexTools.splitXmlnsOnFormat": { },
"type": "boolean",
"default": true, "basexTools.removeCommentsOnMinify": {
"description": "Put each xmlns attribute on a new line when formatting XML.", "type": "boolean",
"scope": "resource" "default": false,
}, "description": "Remove XML comments during minification.",
"basexTools.xmlFormatterImplementation": { "scope": "resource"
"type": "string", },
"enum": [ "basexTools.splitAttributesOnFormat": {
"classic", "type": "boolean",
"v2" "default": false,
], "description": "Put each attribute on a new line when formatting XML. Overrides `basexTools.splitXmlnsOnFormat` if set to `true`.",
"default": "v2", "scope": "resource"
"description": "Supported XML Formatters: classic", },
"scope": "window" "basexTools.splitXmlnsOnFormat": {
}, "type": "boolean",
"basexTools.xqueryExecutionArguments": { "default": true,
"type": "array", "description": "Put each xmlns attribute on a new line when formatting XML.",
"default": [ "scope": "resource"
"-xquery", },
"$(script)", "basexTools.xmlFormatterImplementation": {
"-in", "type": "string",
"$(input)", "enum": [
"-out", "classic",
"$(input).output.xml" "v2"
], ],
"description": "Arguments to be passed to the XQuery execution engine.", "default": "v2",
"scope": "window" "description": "Supported XML Formatters: classic",
}, "scope": "window"
"basexTools.xqueryExecutionEngine": { },
"type": "string", "basexTools.xqueryExecutionArguments": {
"default": "", "type": "array",
"description": "The full path to the executable to run when executing XQuery scripts.", "default": [
"scope": "window" "-xquery",
}, "$(script)",
"basexTools.xqueryExecutionInputLimit": { "-in",
"type": "integer", "$(input)",
"default": 100, "-out",
"description": "The maximum number of input files to enumerate when executing XQuery scripts.", "$(input).output.xml"
"scope": "window" ],
}, "description": "Arguments to be passed to the XQuery execution engine.",
"basexTools.xqueryExecutionInputSearchPattern": { "scope": "window"
"type": "string", },
"default": "**/*.xml", "basexTools.xqueryExecutionEngine": {
"description": "The pattern used to search for input XML files when executing XQuery scripts.", "type": "string",
"scope": "window" "default": "",
"description": "The full path to the executable to run when executing XQuery scripts.",
"scope": "window"
},
"basexTools.xqueryExecutionInputLimit": {
"type": "integer",
"default": 100,
"description": "The maximum number of input files to enumerate when executing XQuery scripts.",
"scope": "window"
},
"basexTools.xqueryExecutionInputSearchPattern": {
"type": "string",
"default": "**/*.xml",
"description": "The pattern used to search for input XML files when executing XQuery scripts.",
"scope": "window"
}
} }
} }
}, ],
"grammars": [ "grammars": [
{ {
"language": "xquery", "language": "xquery",
@ -289,4 +304,4 @@
"@xmldom/xmldom": "^0.8.1", "@xmldom/xmldom": "^0.8.1",
"xpath": "0.0.32" "xpath": "0.0.32"
} }
} }

5
src/CHANGELOG.md Normal file
View file

@ -0,0 +1,5 @@
# 0.0.48
* Fix xmlToText #6
* FIX outline all vars
# 0.0.47

View file

@ -1,4 +1,4 @@
export * from "./formatAsXml"; export * from "./formatAsXml";
export * from "./minifyXml"; export * from "./minifyXml";
export * from "./xmlToText"; export * from "./xmlToText";
export * from "./textToXml";

View file

@ -1,33 +0,0 @@
import { workspace } from "vscode";
import { ProviderResult, Range, TextEdit, TextEditor, Selection } 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 textToXml(textEditor: TextEditor): void {
textEditor.edit(textEdit => {
const selections = textEditor.selections;
selections.forEach(selection => {
if (selection.isEmpty) {
selection = new Selection(
textEditor.document.positionAt(0),
textEditor.document.positionAt(textEditor.document.getText().length)
);
}
const txt = textEditor.document.getText(new Range(selection.start, selection.end));
const transformed = txt
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&amp;/g, "&")
// tslint:disable-next-line
.replace(/&quot;/g, '"')
.replace(/&apos;/g, "'");
textEdit.replace(selection, transformed);
});
});
}

View file

@ -1,12 +1,7 @@
import { workspace } from "vscode";
import { ProviderResult, Range, TextEdit, TextEditor, Selection } from "vscode";
import { NativeCommands } from "../../common"; import { Range, TextEditor, Selection } from "vscode";
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 xmlToText(textEditor: TextEditor): void { export function xmlToText(textEditor: TextEditor): void {
textEditor.edit(textEdit => { textEditor.edit(textEdit => {
@ -20,9 +15,9 @@ export function xmlToText(textEditor: TextEditor): void {
} }
const txt = textEditor.document.getText(new Range(selection.start, selection.end)); const txt = textEditor.document.getText(new Range(selection.start, selection.end));
const transformed = txt const transformed = txt
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;") .replace(/</g, "&lt;")
.replace(/>/g, "&gt;") .replace(/>/g, "&gt;")
.replace(/&/g, "&amp;")
.replace(/"/g, "&quot;") .replace(/"/g, "&quot;")
.replace(/'/g, "&apos;"); .replace(/'/g, "&apos;");
@ -30,3 +25,27 @@ export function xmlToText(textEditor: TextEditor): void {
}); });
}); });
} }
export function textToXml(textEditor: TextEditor): void {
textEditor.edit(textEdit => {
const selections = textEditor.selections;
selections.forEach(selection => {
if (selection.isEmpty) {
selection = new Selection(
textEditor.document.positionAt(0),
textEditor.document.positionAt(textEditor.document.getText().length)
);
}
const txt = textEditor.document.getText(new Range(selection.start, selection.end));
const transformed = txt
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&amp;/g, "&")
// tslint:disable-next-line
.replace(/&quot;/g, '"')
.replace(/&apos;/g, "'");
textEdit.replace(selection, transformed);
});
});
}

View file

@ -5,12 +5,12 @@ import { channel } from "../common/logger";
// //
// This class handles Symbols // This class handles Symbols
// //
function makeSymbol (name :string,desc :string,icon :vscode.SymbolKind,pos :any) { function makeSymbol(name: string, description: string, icon: vscode.SymbolKind, pos: any) {
const spos = new vscode.Position(pos.sl, pos.sc); const spos = new vscode.Position(pos.sl, pos.sc);
const epos = new vscode.Position(pos.el, pos.ec); const epos = new vscode.Position(pos.el, pos.ec);
const fullrange=new vscode.Range(spos,epos); const fullrange = new vscode.Range(spos, epos);
const selrange=new vscode.Range(spos,spos); const selrange = new vscode.Range(spos, spos);
return new vscode.DocumentSymbol(name,"var", vscode.SymbolKind.Variable, fullrange, selrange); return new vscode.DocumentSymbol(name, description, icon, fullrange, selrange);
} }
export class Symbols implements vscode.DocumentSymbolProvider { export class Symbols implements vscode.DocumentSymbolProvider {
@ -23,23 +23,23 @@ export class Symbols implements vscode.DocumentSymbolProvider {
const symbols: vscode.DocumentSymbol[] = []; const symbols: vscode.DocumentSymbol[] = [];
const text = document.getText(); const text = document.getText();
const linter = new (XQLint as any)(text, { "styleCheck": false }); const linter = new (XQLint as any)(text, { "styleCheck": false });
const xqdoc= linter.getXQDoc(); const xqdoc = linter.getXQDoc();
channel.log(xqdoc.variables); channel.log("got xqdoc");
// type: type, // type: type,
// pos: pos, // pos: pos,
// qname: qname, // qname: qname,
// annotations: {} // annotations: {}
xqdoc.variables.forEach(v => { xqdoc.variables.forEach(v => {
const name = v.name; const name = v.name;
const info =makeSymbol(name,"var", vscode.SymbolKind.Variable,v.pos) const info = makeSymbol(name, "var", vscode.SymbolKind.Variable, v.pos)
symbols.push(info); symbols.push(info);
}); });
xqdoc.functions.forEach(v => { xqdoc.functions.forEach(v => {
const name = v.name; const name = v.name;
const info =makeSymbol(name,"Fu", vscode.SymbolKind.Function,v.pos) const info = makeSymbol(name, "Fu", vscode.SymbolKind.Function, v.pos)
symbols.push(info); symbols.push(info);
}); });
channel.log("Symbols done" + document.uri); channel.log("Symbols done " + document.uri);
return symbols; return symbols;
}; };
} }