Compare commits

..

No commits in common. "master" and "19a57fe6ca344a1de9c6537ad15806ebcb2bbe4a" have entirely different histories.

46 changed files with 3021 additions and 5893 deletions

View file

@ -1,20 +0,0 @@
{
"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": {
}
}

View file

@ -7,7 +7,7 @@ about: Report an issue with the XML formatter.
What seems to be the problem? What seems to be the problem?
#### Formatter Implementation #### Formatter Implementation
Which XML Formatter implementation are you using (the value of your `basexTools.xmlFormatterImplementation` setting). Which XML Formatter implementation are you using (the value of your `xmlTools.xmlFormatterImplementation` setting).
#### XML Tools Version #### XML Tools Version
What version of XML Tools are you using? What version of XML Tools are you using?

1
.gitignore vendored
View file

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

View file

@ -1,5 +0,0 @@
{
"recommendations": [
]
}

3
.vscode/launch.json vendored
View file

@ -2,14 +2,13 @@
{ {
"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": true, "stopOnEntry": false,
"sourceMaps": true, "sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/**/*.js" ], "outFiles": [ "${workspaceRoot}/out/**/*.js" ],
"preLaunchTask": "npm: watch" "preLaunchTask": "npm: watch"

11
.vscode/sftp.json vendored Normal file
View file

@ -0,0 +1,11 @@
{
"name": "My Server",
"host": "localhost",
"protocol": "sftp",
"port": 22,
"username": "username",
"remotePath": "/",
"uploadOnSave": true,
"useTempFile": false,
"openSsh": false
}

View file

@ -1,8 +1,8 @@
node_modules .vscode/**
#out/ .vscode-test/**
src/ out/test/**
tsconfig.json out/**/*.map
.github src/**
.gitignore .gitignore
.vscode tsconfig.json
vsc-extension-quickstart.md

View file

@ -1,14 +1 @@
# 0.1.0 (2023-02-19) Detailed release notes are available [here](https://github.com/DotJoshJohnson/vscode-xml/releases).
Update xqlint to 0.2.0
# 0.0.64 (2023-01-26)
* add simple hover display
* Update `xqlint.d.ts` to support newer `tsc.exe`. This reduces size of vsix from 600kb to 300kb
# 0.0.58
* use xqlint 0.0.14
# 0.0.48
* Fix xmlToText #6
* FIX outline all vars

30
CONTRIBUTING.md Normal file
View file

@ -0,0 +1,30 @@
# Contributing to XML Tools
Welcome and thank you for contributing to **XML Tools for Visual Studio Code**! This document aims to provide an overview of standards and expectations for those interested in contributing to the project.
## Asking Questions
If you have any questions, please ask on Gitter or Twitter instead of submitting an issue.
## Reporting Issues
Before submitting a new issue, please be sure to check for an existing issue that matches yours first. Issues that are waiting for information for more than 30 days will be closed, so please be sure to follow your issues!
## Writing Code
If you would like to contribute code to the project, please follow these conventions:
* Use spaces over tabs (4 spaces per tab is preferred).
* Use double quotes whenever possible instead of single quotes.
* Use **snake-case** for file names.
* Use **PascalCase** for class and interface names.
* Use **camelCase** for all other identifiers unless otherwise specified.
* Prefix private members with an underscore.
* Implement and maintain barrels (`index.ts` files) when creating new folders or files.
* Use constants when referencing a static value more than once in your code.
* Place `else` and `else if` on their own lines.
* Never put opening braces (`{`) on their own line.
* Always use semicolons.
* Always prefer `const` whenever possible and fall back to `let` only if absolutely necessary.
### Branches and Pull Requests
Always develop on a new feature branch in your fork and submit pull requests from that branch to our master branch. Don't worry about changing any version numbers - that happens in its own PR before a release.
### Formatter Changes
For small bug fixes or feature additions, always add a new test case to accompany your change. If you are making large sweeping changes to how the formatter works or leveraging an external dependency for formatting XML, please create a new XmlFormatter implementation.

View file

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2022 Andy Bunce Copyright (c) 2015 Josh Johnson
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -1,55 +1,43 @@
# BaseX Tools for Visual Studio Code # XML Tools for Visual Studio Code
[![Visual Studio Marketplace](https://img.shields.io/vscode-marketplace/v/DotJoshJohnson.xml.svg?style=for-the-badge)](https://marketplace.visualstudio.com/items?itemName=DotJoshJohnson.xml)
[![Visual Studio Marketplace](https://img.shields.io/vscode-marketplace/r/DotJoshJohnson.xml.svg?style=for-the-badge)](https://marketplace.visualstudio.com/items?itemName=DotJoshJohnson.xml)
[![](https://img.shields.io/badge/TWITTER-%40DotJohnson-blue.svg?logo=twitter&style=for-the-badge)](https://twitter.com/DotJoshJohnson)
The vscode-basex extension adds features to support [BaseX](https://basex.org/) development on VSCode. [![](https://img.shields.io/badge/gitter-join_chat-1dce73.svg?style=for-the-badge&logo=gitter-white)](https://gitter.im/vscode-xml/vscode-xml)
For XQuery [![Beerpay](https://img.shields.io/beerpay/DotJoshJohnson/vscode-xml.svg?style=for-the-badge)](https://beerpay.io/DotJoshJohnson/vscode-xml)
* Grammar support for:XQuery 3.1, XQuery update, Full text syntax
* code format
* code completion
* code snippets
* outline symbol view
## Features ## Features
* [XQuery Linting](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xquery-linting) * [XML Formatting](https://github.com/DotJoshJohnson/vscode-xml/wiki/xml-formatting)
* [XQuery Code Completion](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xquery-code-completion) * [XML Tree View](https://github.com/DotJoshJohnson/vscode-xml/wiki/xml-tree-view)
* [XQuery Execution](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xquery-script-execution) * [XPath Evaluation](https://github.com/DotJoshJohnson/vscode-xml/wiki/xpath-evaluation)
* [XQuery source formating](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xquery-source-formating) * [XQuery Linting](https://github.com/DotJoshJohnson/vscode-xml/wiki/xquery-linting)
* [XQuery Execution](https://github.com/DotJoshJohnson/vscode-xml/wiki/xquery-script-execution)
* [XML Formatting](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xml-formatting) * [XQuery Code Completion](https://github.com/DotJoshJohnson/vscode-xml/wiki/xquery-code-completion)
* [XML Tree View](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xml-tree-view)
* [XPath Evaluation](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xpath-evaluation)
## Requirements ## Requirements
* VS Code `1.63.0` or higher * VS Code `1.22.2` or higher
## Extension Settings
* **`xmlTools.enableXmlTreeView`:** Enables the XML Tree View for XML documents.
* **`xmlTools.enableXmlTreeViewMetadata`:** Enables attribute and child element counts in the XML Document view.
* **`xmlTools.enableXmlTreeViewCursorSync`:** Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.
* **`xmlTools.enforcePrettySelfClosingTagOnFormat`:** Ensures a space is added before the forward slash at the end of a self-closing tag.
* **`xmlTools.ignoreDefaultNamespace`:** Ignore default xmlns attributes when evaluating XPath.
* **`xmlTools.persistXPathQuery`:** Remember the last XPath query used.
* **`xmlTools.removeCommentsOnMinify`:** Remove XML comments during minification.
* **`xmlTools.splitAttributesOnFormat`:** Put each attribute on a new line when formatting XML. Overrides `xmlTools.splitXmlnsOnFormat` if set to `true`. (V2 Formatter Only)
* **`xmlTools.splitXmlnsOnFormat`:** Put each xmlns attribute on a new line when formatting XML.
* **`xmlTools.xmlFormatterImplementation`:** Supported XML Formatters: `classic`, `v2`.
* **`xmlTools.xqueryExecutionArguments`:** Arguments to be passed to the XQuery execution engine.
* **`xmlTools.xqueryExecutionEngine`:** The full path to the executable to run when executing XQuery scripts.
## Release Notes ## Release Notes
Detailed release notes are available [here](https://git.quodatum.duckdns.org/apb/vscode-basex/releases). Detailed release notes are available [here](https://github.com/DotJoshJohnson/vscode-xml/releases).
## Issues ## Issues
Run into a bug? Report it [here](https://git.quodatum.duckdns.org/apb/vscode-basex/issues). Run into a bug? Report it [here](https://github.com/DotJoshJohnson/vscode-xml/issues).
## Development
## build
```
npm install
npm install -g typescript #maybe
npm install --global vsce
#
npm run compile
vsce package
```
## Inspiration
This project was created from a fork of [DotJoshJohnson/vscode-xml](https://github.com/DotJoshJohnson/vscode-xml). Much of `DotJoshJohnson/vscode-xml` code dealing with XML has been removed and additional XQuery features added.
The code parsing uses [quodatum/xqlint] which is based on [wcandillon/xqlint]
## Icon Credits ## Icon Credits
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

32
azure-pipelines.yml Normal file
View file

@ -0,0 +1,32 @@
name: "$(Build.SourceBranchName)-$(Build.SourceVersion)$(Rev:.r)"
pr:
- master
trigger:
- "refs/tags/*"
pool:
vmImage: "windows-2019"
steps:
- task: NodeTool@0
inputs:
versionSpec: "10.x"
displayName: "Install NodeJS"
- script: |
npm install -g vsce
displayName: "Install VSCE"
- script: |
npm install
displayName: "NPM Install"
- script: |
vsce package --out "$(Build.ArtifactStagingDirectory)/xml-$(Build.SourceBranchName)-$(Build.SourceVersion).vsix"
displayName: "VSCE Package"
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory)
artifactName: drop

View file

@ -1,19 +1,20 @@
{ {
"comments": { "comments": {
"lineComment": ["(:", ":)"], "lineComment": ["(:", ":)"],
"blockComment": [ "(:", ":)"] "blockComment": [ "(:~", "~:)"]
}, },
"brackets": [ "brackets": [
[ "{", "}" ], [
[ "[", "]" ], "{",
[ "(", ")" ] "}"
], ],
"surroundingPairs": [ [
["{", "}"], "[",
["[", "]"], "]"
["(", ")"], ],
["'", "'"], [
["\"", "\""], "(",
["`", "`"] ")"
]
] ]
} }

View file

@ -1,57 +0,0 @@
# 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}
```

4795
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,131 +1,149 @@
{ {
"name": "vscode-basex", "name": "vscode-basex",
"displayName": "BaseX tools", "displayName": "XML Tools for BaseX",
"description": "BaseX tools: XQuery, XML, XPath Tools for Visual Studio Code", "description": "XML Formatting, XQuery, and XPath Tools for Visual Studio Code",
"version": "0.1.0", "version": "0.0.1",
"preview": true, "preview": false,
"publisher": "quodatum", "publisher": "quodatum",
"author": "Andy Bunce (https://github.com/Quodatum)", "author": {
"name": "Andy Bunce",
"url": "https://github.com/DotJoshJohnson"
},
"license": "MIT", "license": "MIT",
"galleryBanner": { "galleryBanner": {
"color": "#FFFFFF", "color": "#FFFFFF",
"theme": "light" "theme": "light"
}, },
"icon": "resources/basex.png", "icon": "resources/xml.png",
"homepage": "https://github.com/Quodatum/vscode-basex", "homepage": "https://github.com/DotJoshJohnson/vscode-xml",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/Quodatum/vscode-basex.git" "url": "https://github.com/DotJoshJohnson/vscode-xml.git"
}, },
"bugs": { "bugs": {
"url": "https://github.com/Quodatum/vscode-basex/issues" "url": "https://github.com/DotJoshJohnson/vscode-xml/issues"
}, },
"engines": { "engines": {
"vscode": "^1.73.0" "vscode": "^1.63.0"
}, },
"categories": [ "categories": [
"Formatters", "Formatters",
"Programming Languages", "Programming Languages",
"Linters", "Linters",
"Snippets",
"Other" "Other"
], ],
"activationEvents": [ "activationEvents": [
"onCommand:basexTools.evaluateXPath", "onCommand:xmlTools.evaluateXPath",
"onCommand:basexTools.executeXQuery", "onCommand:xmlTools.executeXQuery",
"onCommand:basexTools.formatAsXml", "onCommand:xmlTools.formatAsXml",
"onCommand:basexTools.textToXml", "onCommand:xmlTools.textToXml",
"onCommand:basexTools.xmlToText", "onCommand:xmlTools.xmlToText",
"onCommand:basexTools.minifyXml", "onCommand:xmlTools.minifyXml",
"onCommand:basexTools.xqLintReport",
"onLanguage:xml", "onLanguage:xml",
"onLanguage:xquery", "onLanguage:xquery",
"onLanguage:xsl" "onLanguage:xsl"
], ],
"main": "./out/extension.js", "main": "./out/extension",
"contributes": { "contributes": {
"commands": [ "commands": [
{ {
"command": "basexTools.evaluateXPath", "command": "xmlTools.evaluateXPath",
"title": "BaseX Tools: Evaluate XPath" "title": "XML Tools: Evaluate XPath"
}, },
{ {
"command": "basexTools.executeXQuery", "command": "xmlTools.executeXQuery",
"title": "BaseX Tools: Execute XQuery" "title": "XML Tools: Execute XQuery"
}, },
{ {
"command": "basexTools.formatAsXml", "command": "xmlTools.formatAsXml",
"title": "BaseX Tools: Format as XML" "title": "XML Tools: Format as XML"
}, },
{ {
"command": "basexTools.textToXml", "command": "xmlTools.textToXml",
"title": "BaseX Tools: Convert text to XML (&lt;&gt; -> <>)" "title": "XML Tools: Convert text to XML (&lt;&gt; -> <>)"
}, },
{ {
"command": "basexTools.xmlToText", "command": "xmlTools.xmlToText",
"title": "BaseX Tools: Convert XML to text (<> -> &lt;&gt;)" "title": "XML Tools: Convert XML to text (<> -> &lt;&gt;)"
}, },
{ {
"command": "basexTools.getCurrentXPath", "command": "xmlTools.getCurrentXPath",
"title": "BaseX Tools: Get Current XPath" "title": "XML Tools: Get Current XPath"
}, },
{ {
"command": "basexTools.minifyXml", "command": "xmlTools.minifyXml",
"title": "BaseX Tools: Minify XML" "title": "XML Tools: Minify XML"
},
{
"command": "basexTools.xqLintReport",
"title": "BaseX Tools: Analysis of current location in Xquery source"
} }
], ],
"configuration": [ "configuration": {
{ "title": "XML Tools Configuration",
"id": "xmltree", "type": "object",
"title": "XML tree view ",
"properties": { "properties": {
"basexTools.xmlTree.enableTreeView": { "xmlTools.enableXmlTreeView": {
"type": "boolean", "type": "boolean",
"default": false, "default": true,
"description": "Enables the XML Document view in the explorer for XML documents.", "description": "Enables the XML Document view in the explorer for XML documents.",
"scope": "window" "scope": "window"
}, },
"basexTools.xmlTree.enableViewMetadata": { "xmlTools.enableXmlTreeViewMetadata": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Enables attribute and child element counts in the XML Document view.", "description": "Enables attribute and child element counts in the XML Document view.",
"scope": "window" "scope": "window"
}, },
"basexTools.xmlTree.enableViewCursorSync": { "xmlTools.enableXmlTreeViewCursorSync": {
"type": "boolean", "type": "boolean",
"default": false, "default": false,
"description": "Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.", "description": "Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.",
"scope": "window" "scope": "window"
}
}
}, },
{ "xmlTools.enforcePrettySelfClosingTagOnFormat": {
"id": "xpath", "type": "boolean",
"title": "XPath ", "default": false,
"properties": { "description": "Enforces a space before the forward slash at the end of a self-closing XML tag.",
"basexTools.xpath.ignoreDefaultNamespace": { "scope": "resource"
},
"xmlTools.ignoreDefaultNamespace": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Ignore default xmlns attributes when evaluating XPath.", "description": "Ignore default xmlns attributes when evaluating XPath.",
"scope": "window" "scope": "window"
}, },
"basexTools.xpath.persistXPathQuery": { "xmlTools.persistXPathQuery": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Remember the last XPath query used.", "description": "Remember the last XPath query used.",
"scope": "window" "scope": "window"
}
}
}, },
{ "xmlTools.removeCommentsOnMinify": {
"id": "xquery", "type": "boolean",
"title": "XQuery ", "default": false,
"properties": { "description": "Remove XML comments during minification.",
"basexTools.xquery.executionArguments": { "scope": "resource"
},
"xmlTools.splitAttributesOnFormat": {
"type": "boolean",
"default": false,
"description": "Put each attribute on a new line when formatting XML. Overrides `xmlTools.splitXmlnsOnFormat` if set to `true`.",
"scope": "resource"
},
"xmlTools.splitXmlnsOnFormat": {
"type": "boolean",
"default": true,
"description": "Put each xmlns attribute on a new line when formatting XML.",
"scope": "resource"
},
"xmlTools.xmlFormatterImplementation": {
"type": "string",
"enum": [
"classic",
"v2"
],
"default": "v2",
"description": "Supported XML Formatters: classic",
"scope": "window"
},
"xmlTools.xqueryExecutionArguments": {
"type": "array", "type": "array",
"default": [ "default": [
"-xquery", "-xquery",
@ -138,19 +156,19 @@
"description": "Arguments to be passed to the XQuery execution engine.", "description": "Arguments to be passed to the XQuery execution engine.",
"scope": "window" "scope": "window"
}, },
"basexTools.xquery.executionEngine": { "xmlTools.xqueryExecutionEngine": {
"type": "string", "type": "string",
"default": "", "default": "",
"description": "The full path to the executable to run when executing XQuery scripts.", "description": "The full path to the executable to run when executing XQuery scripts.",
"scope": "window" "scope": "window"
}, },
"basexTools.xquery.executionInputLimit": { "xmlTools.xqueryExecutionInputLimit": {
"type": "integer", "type": "integer",
"default": 100, "default": 100,
"description": "The maximum number of input files to enumerate when executing XQuery scripts.", "description": "The maximum number of input files to enumerate when executing XQuery scripts.",
"scope": "window" "scope": "window"
}, },
"basexTools.xquery.executionInputSearchPattern": { "xmlTools.xqueryExecutionInputSearchPattern": {
"type": "string", "type": "string",
"default": "**/*.xml", "default": "**/*.xml",
"description": "The pattern used to search for input XML files when executing XQuery scripts.", "description": "The pattern used to search for input XML files when executing XQuery scripts.",
@ -158,47 +176,6 @@
} }
} }
}, },
{
"title": "BaseX Tools ",
"type": "object",
"properties": {
"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"
},
"basexTools.removeCommentsOnMinify": {
"type": "boolean",
"default": false,
"description": "Remove XML comments during minification.",
"scope": "resource"
},
"basexTools.splitAttributesOnFormat": {
"type": "boolean",
"default": false,
"description": "Put each attribute on a new line when formatting XML. Overrides `basexTools.splitXmlnsOnFormat` if set to `true`.",
"scope": "resource"
},
"basexTools.splitXmlnsOnFormat": {
"type": "boolean",
"default": true,
"description": "Put each xmlns attribute on a new line when formatting XML.",
"scope": "resource"
},
"basexTools.xmlFormatterImplementation": {
"type": "string",
"enum": [
"classic",
"v2"
],
"default": "v2",
"description": "Supported XML Formatters: classic",
"scope": "window"
}
}
}
],
"grammars": [ "grammars": [
{ {
"language": "xquery", "language": "xquery",
@ -206,20 +183,14 @@
"scopeName": "source.xquery" "scopeName": "source.xquery"
} }
], ],
"snippets": [
{
"language": "xquery",
"path": "./snippets.jsonc"
}
],
"keybindings": [ "keybindings": [
{ {
"key": "ctrl+shift+alt+x", "key": "ctrl+shift+alt+x",
"command": "basexTools.evaluateXPath" "command": "xmlTools.evaluateXPath"
}, },
{ {
"key": "ctrl+shift+alt+b", "key": "ctrl+shift+alt+b",
"command": "basexTools.formatAsXml" "command": "xmlTools.formatAsXml"
} }
], ],
"languages": [ "languages": [
@ -232,8 +203,7 @@
".xsd", ".xsd",
".xsl", ".xsl",
".plist", ".plist",
".mobileconfig", ".mobileconfig"
".sch"
] ]
}, },
{ {
@ -255,25 +225,25 @@
"menus": { "menus": {
"commandPalette": [ "commandPalette": [
{ {
"command": "basexTools.evaluateXPath", "command": "xmlTools.evaluateXPath",
"when": "editorLangId == xml" "when": "editorLangId == xml"
}, },
{ {
"command": "basexTools.executeXQuery", "command": "xmlTools.executeXQuery",
"when": "editorLangId == xquery" "when": "editorLangId == xquery"
}, },
{ {
"command": "basexTools.getCurrentXPath", "command": "xmlTools.getCurrentXPath",
"when": "editorLangId == xml" "when": "editorLangId == xml"
}, },
{ {
"command": "basexTools.minifyXml", "command": "xmlTools.minifyXml",
"when": "editorLangId == xml" "when": "editorLangId == xml"
} }
], ],
"editor/context": [ "editor/context": [
{ {
"command": "basexTools.minifyXml", "command": "xmlTools.minifyXml",
"group": "1_modification@100", "group": "1_modification@100",
"when": "editorLangId == 'xml'" "when": "editorLangId == 'xml'"
} }
@ -290,11 +260,7 @@
} }
}, },
"scripts": { "scripts": {
"vscode:prepublish": "npm run esbuild-base -- --minify", "vscode:prepublish": "npm run compile",
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node",
"esbuild": "npm run esbuild-base -- --sourcemap",
"esbuild-watch": "npm run esbuild-base -- --sourcemap --watch",
"test-compile": "tsc -p ./",
"compile": "tsc -p ./", "compile": "tsc -p ./",
"watch": "tsc -watch -p ./", "watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint", "pretest": "npm run compile && npm run lint",
@ -302,23 +268,22 @@
"test": "node ./out/test/runTest.js" "test": "node ./out/test/runTest.js"
}, },
"devDependencies": { "devDependencies": {
"@types/vscode": "^1.63.0",
"@types/glob": "^7.2.0", "@types/glob": "^7.2.0",
"@types/mocha": "^9.0.0", "@types/mocha": "^9.0.0",
"@types/node": "^14.18.12", "@types/node": "14.x",
"@types/vscode": "^1.73.0", "@typescript-eslint/eslint-plugin": "^5.9.1",
"@types/xmldom": "^0.1.31", "@typescript-eslint/parser": "^5.9.1",
"@typescript-eslint/eslint-plugin": "^5.13.0", "@types/xmldom": "^0.1.13",
"@typescript-eslint/parser": "^5.13.0", "eslint": "^8.6.0",
"@vscode/test-electron": "^2.1.3",
"esbuild": "^0.14.25",
"eslint": "^8.10.0",
"glob": "^7.2.0", "glob": "^7.2.0",
"mocha": "^9.2.1", "mocha": "^9.1.3",
"typescript": "^4.7.3" "typescript": "^4.5.4",
"@vscode/test-electron": "^2.0.3"
}, },
"dependencies": { "dependencies": {
"@quodatum/xqlint": "^0.2.0", "xmldom": "^0.1.27",
"@xmldom/xmldom": "^0.8.1", "xpath": "0.0.27",
"xpath": "0.0.32" "xqlint": "^0.4.1"
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

BIN
resources/xml.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View file

@ -1,13 +0,0 @@
/* 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);

View file

@ -1,120 +0,0 @@
{
"for": {
"prefix": "for",
"body": "for $${1:item} in ${2:expr}"
},
"return": {
"prefix": "ret",
"body": "return ${1:expr}"
},
"import": {
"prefix": "import",
"body": "import module namespace ${1:ns} = '${2:http://www.example.com/}';",
"description": "Import module"
},
"module": {
"prefix": "module",
"body": "module namespace ${1:ns} = '${2:http://www.example.com}';"
},
"every": {
"prefix": "every",
"body": "every $${1:varname} in ${2:expr} satisfies ${3:expr}"
},
"some": {
"prefix": "some",
"body": "some $${1:varname} in ${2:expr} satisfies ${3:expr}"
},
"function": {
"prefix": "df",
"body": [
"(:~ $${2:name} :)",
"declare function ${1:ns}:${2:name}(){",
"${3:expr}",
"};"
],
"description": "declare a function"
},
"declare variable": {
"prefix": "dv",
"body": [
"(:~ $${1:varname} :)",
"declare variable $${1:varname} := ${2:expr};",
""
],
"description": "declare variable"
},
"switch": {
"prefix": "sw",
"body": [
"switch(${1:foo})",
"case ${2:foo} return ${3:true}",
"default return ${4:false}"
],
"description": "switch statement"
},
"typeswitch": {
"prefix": "type",
"body": [
"typeswitch(${1:foo})",
"case ${2:foo} return ${3:true}",
"default return ${4:false}"
],
"description": "typeswitch statement"
},
"try": {
"prefix": "try",
"body": [
"try { ${1:expr} } ",
"catch ${2:*} { ${3:expr} }"
],
"description": "switch statement"
},
"tumbling": {
"prefix": "tumbling",
"body": [
"for tumbling window $${1:varname} in ${2:expr}",
"start at $${3:start} when ${4:expr}",
"end at $${5:end} when ${6:expr}",
"return ${7:expr}"
],
"description": "tumbling window"
},
"sliding": {
"prefix": "sliding",
"body": [
"for sliding window $${1:varname} in ${2:expr}",
"start at $${3:start} when ${4:expr}",
"end at $${5:end} when ${6:expr}",
"return ${7:expr}"
],
"description": "sliding window"
}
}
//snippet if
// if(${1:true}) then ${2:expr} else ${3:true}
// default return ${4:false}
//snippet let
// let $${1:varname} := ${2:expr}
//snippet group
// group by $${1:varname} := ${2:expr}
//snippet order
// order by ${1:expr} ${2:descending}
//snippet stable
// stable order by ${1:expr}
//snippet count
// count $${1:varname}
//snippet ordered
// ordered { ${1:expr} }
//snippet unordered
// unordered { ${1:expr} }
//snippet treat
// treat as ${1:expr}
//snippet castable
// castable as ${1:atomicType}
//snippet cast
// cast as ${1:atomicType}

View file

@ -1,46 +0,0 @@
declare module '@quodatum/xqlint'{
import { Position } from "vscode";
export class XQLint{
constructor(source :string, opts? :object);
public getCompletions(pos :object): [object];
public getXQDoc() :XQDoc;
public getAST(pos? :Position) :any;
public getSctx(pos? :Position) :any;
public getErrors() :[Marker];
public getWarnings() :[Marker];
}
export class Marker{
pos: Position;
type: string;
level: string;
message: string;
}
export class XQDoc{
moduleNamespace: string;
description: string;
variables: [VarDecl];
functions: [FunDecl];
}
export interface VarDecl {
name: string;
type: string;
occurrence?: string;
description: string;
pos: any;
}
export interface FunDecl {
name: string;
arity: number;
params: string[]; // name
description: string;
pos: boolean;
}
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

@ -1,26 +1,26 @@
import { workspace, Uri } from "vscode"; import { workspace, Uri } from "vscode";
const ExtensionTopLevelSection = "basexTools"; const ExtensionTopLevelSection = "xmlTools";
export class Configuration { export class Configuration {
static get enableXmlTreeView(): boolean { static get enableXmlTreeView(): boolean {
return this._getForWindow<boolean>("xmlTree.enableTreeView"); return this._getForWindow<boolean>("enableXmlTreeView");
} }
static get enableXmlTreeViewMetadata(): boolean { static get enableXmlTreeViewMetadata(): boolean {
return this._getForWindow<boolean>("xmlTree.enableViewMetadata"); return this._getForWindow<boolean>("enableXmlTreeViewMetadata");
} }
static get enableXmlTreeViewCursorSync(): boolean { static get enableXmlTreeViewCursorSync(): boolean {
return this._getForWindow<boolean>("xmlTree.enableViewCursorSync"); return this._getForWindow<boolean>("enableXmlTreeViewCursorSync");
} }
static get ignoreDefaultNamespace(): boolean { static get ignoreDefaultNamespace(): boolean {
return this._getForWindow<boolean>("xpath.ignoreDefaultNamespace"); return this._getForWindow<boolean>("ignoreDefaultNamespace");
} }
static get persistXPathQuery(): boolean { static get persistXPathQuery(): boolean {
return this._getForWindow<boolean>("xpath.persistXPathQuery"); return this._getForWindow<boolean>("persistXPathQuery");
} }
static get xmlFormatterImplementation(): string { static get xmlFormatterImplementation(): string {
@ -28,19 +28,19 @@ export class Configuration {
} }
static get xqueryExecutionArguments(): string[] { static get xqueryExecutionArguments(): string[] {
return this._getForWindow<string[]>("xquery.executionArguments"); return this._getForWindow<string[]>("xqueryExecutionArguments");
} }
static get xqueryExecutionEngine(): string { static get xqueryExecutionEngine(): string {
return this._getForWindow<string>("xquery.executionEngine"); return this._getForWindow<string>("xqueryExecutionEngine");
} }
static get xqueryExecutionInputLimit(): number { static get xqueryExecutionInputLimit(): number {
return this._getForWindow<number>("xquery.executionInputLimit"); return this._getForWindow<number>("xqueryExecutionInputLimit");
} }
static get xqueryExecutionInputSearchPattern(): string { static get xqueryExecutionInputSearchPattern(): string {
return this._getForWindow<string>("xquery.executionInputSearchPattern"); return this._getForWindow<string>("xqueryExecutionInputSearchPattern");
} }
static enforcePrettySelfClosingTagOnFormat(resource: Uri): boolean { static enforcePrettySelfClosingTagOnFormat(resource: Uri): boolean {

View file

@ -3,4 +3,3 @@ 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";

View file

@ -1,44 +0,0 @@
// debug messages
import { OutputChannel, window } from "vscode";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ver = require("@quodatum/xqlint").version;
const _channel:OutputChannel = window.createOutputChannel("BaseX");
function logdate(){
return (new Date()).toISOString().slice(0, 19).replace(/-/g, "/").replace("T", " ");
}
const replacerFunc = () => {
const visited = new WeakSet();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (key :any, value :any) => {
if (typeof value === "object" && value !== null) {
if (visited.has(value)) {
return;
}
visited.add(value);
}
return value;
};
};
export function dump(obj :object) {
return JSON.stringify(obj,replacerFunc(),1)
}
export class channel {
static log(msg: string) :void{
_channel.appendLine("["+logdate()+"] "+msg)
}
static appendLine(msg: string) :void{
_channel.appendLine(msg)
}
static dir(obj: object) :void{
_channel.appendLine(dump(obj))
}
static show() :void{
_channel.show
}
}
channel.log("started, XQLint version: "+ver);
_channel.show

View file

@ -1,6 +1,6 @@
import { CompletionItem, CompletionItemKind, CompletionItemProvider, Position, TextDocument } from "vscode"; import { CompletionItem, CompletionItemKind, CompletionItemProvider, Position, TextDocument } from "vscode";
import { XQLint} from "@quodatum/xqlint";
const XQLint = require("xqlint").XQLint;
export class XQueryCompletionItemProvider implements CompletionItemProvider { export class XQueryCompletionItemProvider implements CompletionItemProvider {
@ -24,9 +24,7 @@ export class XQueryCompletionItemProvider implements CompletionItemProvider {
case "function": case "function":
completionItem.kind = CompletionItemKind.Function; completionItem.kind = CompletionItemKind.Function;
// eslint-disable-next-line no-case-declarations
const funcStart = (xqLintCompletionItem.value.indexOf(":") + 1); const funcStart = (xqLintCompletionItem.value.indexOf(":") + 1);
// eslint-disable-next-line no-case-declarations
const funcEnd = xqLintCompletionItem.value.indexOf("("); const funcEnd = xqLintCompletionItem.value.indexOf("(");
completionItem.insertText = xqLintCompletionItem.value.substring(funcStart, funcEnd); completionItem.insertText = xqLintCompletionItem.value.substring(funcStart, funcEnd);

View file

@ -1,13 +1,11 @@
/* eslint-disable @typescript-eslint/no-namespace */
export namespace commands { export namespace commands {
export const evaluateXPath = "basexTools.evaluateXPath"; export const evaluateXPath = "xmlTools.evaluateXPath";
export const executeXQuery = "basexTools.executeXQuery"; export const executeXQuery = "xmlTools.executeXQuery";
export const formatAsXml = "basexTools.formatAsXml"; export const formatAsXml = "xmlTools.formatAsXml";
export const xmlToText = "basexTools.xmlToText"; export const xmlToText = "xmlTools.xmlToText";
export const textToXml = "basexTools.textToXml"; export const textToXml = "xmlTools.textToXml";
export const getCurrentXPath = "basexTools.getCurrentXPath"; export const getCurrentXPath = "xmlTools.getCurrentXPath";
export const minifyXml = "basexTools.minifyXml"; export const minifyXml = "xmlTools.minifyXml";
export const xqLintReport = "basexTools.xqLintReport";
} }
export namespace contextKeys { export namespace contextKeys {

View file

@ -1,27 +1,22 @@
import { import {
commands, languages, window, ExtensionContext, commands, languages, window, workspace, ExtensionContext, Memento,
TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind, DiagnosticCollection TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind, DiagnosticCollection
} 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";
import { XmlFormatterFactory, XmlFormattingEditProvider } from "./formatting"; import { XmlFormatterFactory, XmlFormattingEditProvider } from "./formatting";
import { formatAsXml, minifyXml, xmlToText, textToXml } from "./formatting/commands"; import { formatAsXml, minifyXml, xmlToText, textToXml } from "./formatting/commands";
import { XQueryLinter,xqLintReport } from "./linting"; import { XQueryLinter } from "./linting";
import { XmlTreeDataProvider } from "./tree-view"; import { XmlTreeDataProvider } from "./tree-view";
import { evaluateXPath, getCurrentXPath } from "./xpath/commands"; 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/xquery-formatting-provider";
import { Symbols } from './symbols/symbols';
import { XQueryHoverProvider } from './hover/hover';
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)];
@ -34,30 +29,16 @@ export function activate(context: ExtensionContext) {
/* Formatting Features */ /* Formatting Features */
const xmlFormattingEditProvider = new XmlFormattingEditProvider(XmlFormatterFactory.getXmlFormatter()); const xmlFormattingEditProvider = new XmlFormattingEditProvider(XmlFormatterFactory.getXmlFormatter());
const xqueryFormattingEditProvider = new XQueryFormatter();
context.subscriptions.push( context.subscriptions.push(
commands.registerTextEditorCommand(constants.commands.formatAsXml, formatAsXml), commands.registerTextEditorCommand(constants.commands.formatAsXml, formatAsXml),
commands.registerTextEditorCommand(constants.commands.xmlToText, xmlToText), commands.registerTextEditorCommand(constants.commands.xmlToText, xmlToText),
commands.registerTextEditorCommand(constants.commands.textToXml, textToXml), commands.registerTextEditorCommand(constants.commands.textToXml, textToXml),
commands.registerTextEditorCommand(constants.commands.minifyXml, minifyXml), commands.registerTextEditorCommand(constants.commands.minifyXml, minifyXml),
commands.registerTextEditorCommand(constants.commands.xqLintReport, xqLintReport),
languages.registerDocumentFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider), languages.registerDocumentFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider),
languages.registerDocumentRangeFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider), languages.registerDocumentRangeFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider)
languages.registerDocumentFormattingEditProvider(xqueryDocSelector, xqueryFormattingEditProvider),
languages.registerDocumentRangeFormattingEditProvider(xqueryDocSelector, xqueryFormattingEditProvider)
); );
// symbols
const symbols = new Symbols();
context.subscriptions.push(languages.registerDocumentSymbolProvider(constants.languageIds.xquery, symbols));
// hover
const hover = new XQueryHoverProvider();
context.subscriptions.push(languages.registerHoverProvider(constants.languageIds.xquery, hover));
/* Linting Features */ /* Linting Features */
diagnosticCollectionXQuery = languages.createDiagnosticCollection(constants.diagnosticCollections.xquery); diagnosticCollectionXQuery = languages.createDiagnosticCollection(constants.diagnosticCollections.xquery);
context.subscriptions.push( context.subscriptions.push(
@ -94,13 +75,13 @@ 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

@ -1,9 +1,12 @@
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,5 +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,7 +1,10 @@
import { Range, TextEditor, TextEditorEdit } from "vscode"; import { workspace } from "vscode";
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
import * as constants from "../../constants";
import { XmlFormatterFactory } from "../xml-formatter"; import { XmlFormatterFactory } from "../xml-formatter";
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
import { XmlFormattingOptionsFactory } from "../xml-formatting-options"; import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
export function minifyXml(editor: TextEditor, edit: TextEditorEdit): void { export function minifyXml(editor: TextEditor, edit: TextEditorEdit): void {

View file

@ -0,0 +1,33 @@
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,7 +1,12 @@
import { workspace } from "vscode";
import { ProviderResult, Range, TextEdit, TextEditor, Selection } from "vscode";
import { Range, 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 xmlToText(textEditor: TextEditor): void { export function xmlToText(textEditor: TextEditor): void {
textEditor.edit(textEdit => { textEditor.edit(textEdit => {
@ -15,9 +20,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;");
@ -25,27 +30,3 @@ 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

@ -9,8 +9,8 @@ export class ClassicXmlFormatter implements XmlFormatter {
if (options.splitXmlnsOnFormat) { if (options.splitXmlnsOnFormat) {
xml = xml xml = xml
.replace(/xmlns:/g, "~::~xmlns:") .replace(/xmlns\:/g, "~::~xmlns:")
.replace(/xmlns=/g, "~::~xmlns="); .replace(/xmlns\=/g, "~::~xmlns=");
} }
const parts: string[] = xml.split("~::~"); const parts: string[] = xml.split("~::~");

View file

@ -1,4 +1,3 @@
export * from "./xml-formatter"; export * from "./xml-formatter";
export * from "./xml-formatting-edit-provider"; export * from "./xml-formatting-edit-provider";
export * from "./xml-formatting-options"; export * from "./xml-formatting-options";
export * from "./xquery-formatting-provider";

View file

@ -1,6 +1,6 @@
import { window, workspace } from "vscode";
import { Configuration, ExtensionState } from "../common";
import { Configuration } from "../common";
import * as constants from "../constants"; import * as constants from "../constants";
import { ClassicXmlFormatter } from "./formatters/classic-xml-formatter"; import { ClassicXmlFormatter } from "./formatters/classic-xml-formatter";
import { V2XmlFormatter } from "./formatters/v2-xml-formatter"; import { V2XmlFormatter } from "./formatters/v2-xml-formatter";

View file

@ -1,6 +1,7 @@
import { EndOfLine, FormattingOptions, TextDocument } from "vscode"; import { EndOfLine, FormattingOptions, TextDocument } from "vscode";
import { Configuration } from "../common"; import { Configuration } from "../common";
import * as constants from "../constants";
export interface XmlFormattingOptions { export interface XmlFormattingOptions {
editorOptions: FormattingOptions; editorOptions: FormattingOptions;

View file

@ -1,33 +0,0 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// format xquery
import { XQLint, CodeFormatter } from "@quodatum/xqlint";
import { CancellationToken, DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider,
FormattingOptions, ProviderResult,Range,
TextDocument, TextEdit} from "vscode";
import { channel } from "../common/logger";
function format(xquery: string,document: TextDocument): string {
channel.log("XQueryFormatter" + document.uri);
const linter = new (XQLint as any)(xquery, { "styleCheck": false });
channel.appendLine(" linter hasSyntaxError: " + 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;
}
export class XQueryFormatter implements DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider{
provideDocumentFormattingEdits(document: TextDocument, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]> {
const lastLine = document.lineAt(document.lineCount - 1);
const documentRange = new Range(document.positionAt(0), lastLine.range.end);
return this.provideDocumentRangeFormattingEdits(document, documentRange, options, token);
}
provideDocumentRangeFormattingEdits(document: TextDocument, range: Range, _options: FormattingOptions, _token: CancellationToken): ProviderResult<TextEdit[]> {
const selected = document.getText(range);
const result = format(selected, document);
return [TextEdit.replace(range, result)];
}
}

View file

@ -1,28 +0,0 @@
// xquery hover
import { CancellationToken, Hover, HoverProvider, Position, TextDocument } from "vscode";
import { XQLint} from "@quodatum/xqlint";
export class XQueryHoverProvider implements HoverProvider {
public provideHover(
document: TextDocument,
position: Position,
token: CancellationToken
): Hover | null {
const linter = new XQLint(document.getText());
const node=linter.getAST(position);
//const sctx=linter.getCompletions(position);
//channel.log("Hover: " + node.name);
//const dx=dump(node);
//channel.appendLine(dx);
const range = document.getWordRangeAtPosition(position);
const word = document.getText(range);
return new Hover(`XQuery Hover info: ${word} at ${position.line}: ${position.character}
value: ${ node.value }, name: ${ node.name }
`);
return null; //if there is no information to show
}
}

View file

@ -1,2 +1 @@
export * from "./xquery-linter"; export * from "./xquery-linter";
export * from "./report";

View file

@ -1,19 +0,0 @@
import { TextEditor } from "vscode";
import { XQLint} from "@quodatum/xqlint";
import { channel,dump } from "../common/logger";
export function xqLintReport(textEditor: TextEditor): void {
const linter = new XQLint(textEditor.document.getText());
textEditor.edit(textEdit => {
const selections = textEditor.selections;
selections.forEach(selection => {
const pos=selection.start.translate(1,1); //@TODO
const node=linter.getAST(pos);
const sctx=linter.getCompletions(pos);
const dx=dump(node);
channel.appendLine(dx);
});
});
}

View file

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

View file

@ -1,59 +0,0 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { VarDecl, FunDecl, XQLint } from '@quodatum/xqlint';
import {SymbolKind, DocumentSymbol, DocumentSymbolProvider,
Range, Position, TextDocument,CancellationToken} from 'vscode';
import { channel } from "../common/logger";
//
// This class handles XQuery Symbols
//
function makeSymbol(name: string, description: string, icon: SymbolKind, pos: any) {
const spos = new Position(pos.sl, pos.sc);
const epos = new Position(pos.el, pos.ec);
const fullrange = new Range(spos, epos);
const selrange = new Range(spos, spos);
return new DocumentSymbol(name, description, icon, fullrange, selrange);
}
export class Symbols implements DocumentSymbolProvider {
provideDocumentSymbols = async (
document: TextDocument,
token: CancellationToken
): Promise<DocumentSymbol[]> => {
channel.log("Symbols: " + document.uri);
const symbols: DocumentSymbol[] = [];
const text = document.getText();
const linter = new XQLint(text, { "styleCheck": false });
const xqdoc = linter.getXQDoc();
channel.log("got xqdoc");
// type: type,
// pos: pos,
// qname: qname,
// annotations: {}
xqdoc.variables.forEach(function (v: VarDecl): void {
const name = "$" + v.name;
const description="about this variable, some doc here";
channel.log(name + v);
const info = makeSymbol(name, description, SymbolKind.Variable, v.pos);
symbols.push(info);
});
xqdoc.functions.forEach(function (f: FunDecl) {
const name = f.name + "#" + f.params.length;
const description="about this function, some doc here";
channel.log(name + f);
const info = makeSymbol(name, description, SymbolKind.Function, f.pos);
// info.children=[];
// f.params.forEach(function(paramName: string){
// info.children.push(makeSymbol(paramName, "", SymbolKind.Variable, f.pos))
// });
symbols.push(info);
});
channel.log("Symbols done " + document.uri);
return symbols;
};
}

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/xmldom"; import { DOMParser } from "xmldom";
import { Configuration, NativeCommands, XmlTraverser } from "../common"; import { Configuration, NativeCommands, XmlTraverser } from "../common";
import * as constants from "../constants"; import * as constants from "../constants";
@ -15,7 +15,6 @@ 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();
@ -135,7 +134,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(null); this._onDidChangeTreeData.fire(0);
return; return;
} }
@ -163,7 +162,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
this._xmlTraverser.xmlDocument = this._xmlDocument; this._xmlTraverser.xmlDocument = this._xmlDocument;
} }
this._onDidChangeTreeData.fire(this.activeEditor.document.uri); this._onDidChangeTreeData.fire(0);
} }
} }

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/xmldom"; import { DOMParser } from "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/xmldom"; import { DOMParser } from "xmldom";
export class EvaluatorResult { export class EvaluatorResult {
type: EvaluatorResultType; type: EvaluatorResultType;

View file

@ -1,4 +1,4 @@
import child_process = require("child_process"); const child_process = require("child_process");
export class ChildProcess { export class ChildProcess {
static async spawn(executable: string, args: string[]): Promise<void> { static async spawn(executable: string, args: string[]): Promise<void> {