Compare commits
26 commits
19a57fe6ca
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e5d06b871 | |||
| 8d47e56dfa | |||
| 497f7bb526 | |||
| b2f40425e3 | |||
| 2b717e39e6 | |||
| 6d074b29c9 | |||
| 52237c8267 | |||
| 0541ecfcad | |||
| 484710a1b2 | |||
| 5bc83682a5 | |||
| b3f47dc553 | |||
| a0b3d96f38 | |||
| 80d5ceea19 | |||
| 47baf6f2b9 | |||
| cfc8ba3817 | |||
| 475943053c | |||
| e945532956 | |||
| 19b4f84ce5 | |||
| 280547a741 | |||
| 9dd58b2b70 | |||
| ee6e911216 | |||
| 560628c7de | |||
| a208e502ea | |||
| c275d88f77 | |||
| 4cbf4cb568 | |||
| 6f919dd209 |
46 changed files with 5891 additions and 3019 deletions
20
.eslintrc.json
Normal file
20
.eslintrc.json
Normal 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": {
|
||||
}
|
||||
}
|
||||
2
.github/ISSUE_TEMPLATE/xml-formatter.md
vendored
2
.github/ISSUE_TEMPLATE/xml-formatter.md
vendored
|
|
@ -7,7 +7,7 @@ about: Report an issue with the XML formatter.
|
|||
What seems to be the problem?
|
||||
|
||||
#### Formatter Implementation
|
||||
Which XML Formatter implementation are you using (the value of your `xmlTools.xmlFormatterImplementation` setting).
|
||||
Which XML Formatter implementation are you using (the value of your `basexTools.xmlFormatterImplementation` setting).
|
||||
|
||||
#### XML Tools Version
|
||||
What version of XML Tools are you using?
|
||||
|
|
|
|||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@ out
|
|||
node_modules
|
||||
.vscode-test/
|
||||
/*.vsix
|
||||
|
||||
|
|
|
|||
5
.vscode/extensions.json
vendored
Normal file
5
.vscode/extensions.json
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"recommendations": [
|
||||
|
||||
]
|
||||
}
|
||||
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
|
|
@ -2,13 +2,14 @@
|
|||
{
|
||||
"version": "0.1.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"name": "Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
|
||||
"stopOnEntry": false,
|
||||
"stopOnEntry": true,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [ "${workspaceRoot}/out/**/*.js" ],
|
||||
"preLaunchTask": "npm: watch"
|
||||
|
|
|
|||
11
.vscode/sftp.json
vendored
11
.vscode/sftp.json
vendored
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"name": "My Server",
|
||||
"host": "localhost",
|
||||
"protocol": "sftp",
|
||||
"port": 22,
|
||||
"username": "username",
|
||||
"remotePath": "/",
|
||||
"uploadOnSave": true,
|
||||
"useTempFile": false,
|
||||
"openSsh": false
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
.vscode/**
|
||||
.vscode-test/**
|
||||
out/test/**
|
||||
out/**/*.map
|
||||
src/**
|
||||
.gitignore
|
||||
node_modules
|
||||
#out/
|
||||
src/
|
||||
tsconfig.json
|
||||
vsc-extension-quickstart.md
|
||||
.github
|
||||
.gitignore
|
||||
.vscode
|
||||
|
||||
|
|
|
|||
15
CHANGELOG.md
15
CHANGELOG.md
|
|
@ -1 +1,14 @@
|
|||
Detailed release notes are available [here](https://github.com/DotJoshJohnson/vscode-xml/releases).
|
||||
# 0.1.0 (2023-02-19)
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
# 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.
|
||||
2
LICENSE
2
LICENSE
|
|
@ -1,6 +1,6 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Josh Johnson
|
||||
Copyright (c) 2022 Andy Bunce
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
|||
70
README.md
70
README.md
|
|
@ -1,43 +1,55 @@
|
|||
# XML Tools for Visual Studio Code
|
||||
[](https://marketplace.visualstudio.com/items?itemName=DotJoshJohnson.xml)
|
||||
[](https://marketplace.visualstudio.com/items?itemName=DotJoshJohnson.xml)
|
||||
# BaseX Tools for Visual Studio Code
|
||||
|
||||
[](https://twitter.com/DotJoshJohnson)
|
||||
[](https://gitter.im/vscode-xml/vscode-xml)
|
||||
[](https://beerpay.io/DotJoshJohnson/vscode-xml)
|
||||
|
||||
The vscode-basex extension adds features to support [BaseX](https://basex.org/) development on VSCode.
|
||||
For XQuery
|
||||
* Grammar support for:XQuery 3.1, XQuery update, Full text syntax
|
||||
* code format
|
||||
* code completion
|
||||
* code snippets
|
||||
* outline symbol view
|
||||
|
||||
## Features
|
||||
* [XML Formatting](https://github.com/DotJoshJohnson/vscode-xml/wiki/xml-formatting)
|
||||
* [XML Tree View](https://github.com/DotJoshJohnson/vscode-xml/wiki/xml-tree-view)
|
||||
* [XPath Evaluation](https://github.com/DotJoshJohnson/vscode-xml/wiki/xpath-evaluation)
|
||||
* [XQuery Linting](https://github.com/DotJoshJohnson/vscode-xml/wiki/xquery-linting)
|
||||
* [XQuery Execution](https://github.com/DotJoshJohnson/vscode-xml/wiki/xquery-script-execution)
|
||||
* [XQuery Code Completion](https://github.com/DotJoshJohnson/vscode-xml/wiki/xquery-code-completion)
|
||||
* [XQuery Linting](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xquery-linting)
|
||||
* [XQuery Code Completion](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xquery-code-completion)
|
||||
* [XQuery Execution](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xquery-script-execution)
|
||||
* [XQuery source formating](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xquery-source-formating)
|
||||
|
||||
* [XML Formatting](https://git.quodatum.duckdns.org/apb/vscode-basex/wiki/xml-formatting)
|
||||
* [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
|
||||
* 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.
|
||||
* VS Code `1.63.0` or higher
|
||||
|
||||
## Release Notes
|
||||
Detailed release notes are available [here](https://github.com/DotJoshJohnson/vscode-xml/releases).
|
||||
Detailed release notes are available [here](https://git.quodatum.duckdns.org/apb/vscode-basex/releases).
|
||||
|
||||
## Issues
|
||||
Run into a bug? Report it [here](https://github.com/DotJoshJohnson/vscode-xml/issues).
|
||||
Run into a bug? Report it [here](https://git.quodatum.duckdns.org/apb/vscode-basex/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
|
||||
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
|
||||
* "At" icon by FreePik from www.flaticon.com
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,20 +1,19 @@
|
|||
{
|
||||
"comments": {
|
||||
"lineComment": ["(:", ":)"],
|
||||
"blockComment": [ "(:~", "~:)"]
|
||||
"blockComment": [ "(:", ":)"]
|
||||
},
|
||||
"brackets": [
|
||||
[
|
||||
"{",
|
||||
"}"
|
||||
[ "{", "}" ],
|
||||
[ "[", "]" ],
|
||||
[ "(", ")" ]
|
||||
],
|
||||
[
|
||||
"[",
|
||||
"]"
|
||||
],
|
||||
[
|
||||
"(",
|
||||
")"
|
||||
]
|
||||
"surroundingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["'", "'"],
|
||||
["\"", "\""],
|
||||
["`", "`"]
|
||||
]
|
||||
}
|
||||
|
|
|
|||
57
notes.md
Normal file
57
notes.md
Normal 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}
|
||||
```
|
||||
4793
package-lock.json
generated
4793
package-lock.json
generated
File diff suppressed because it is too large
Load diff
239
package.json
239
package.json
|
|
@ -1,149 +1,131 @@
|
|||
{
|
||||
"name": "vscode-basex",
|
||||
"displayName": "XML Tools for BaseX",
|
||||
"description": "XML Formatting, XQuery, and XPath Tools for Visual Studio Code",
|
||||
"version": "0.0.1",
|
||||
"preview": false,
|
||||
"displayName": "BaseX tools",
|
||||
"description": "BaseX tools: XQuery, XML, XPath Tools for Visual Studio Code",
|
||||
"version": "0.1.0",
|
||||
"preview": true,
|
||||
"publisher": "quodatum",
|
||||
"author": {
|
||||
"name": "Andy Bunce",
|
||||
"url": "https://github.com/DotJoshJohnson"
|
||||
},
|
||||
"author": "Andy Bunce (https://github.com/Quodatum)",
|
||||
"license": "MIT",
|
||||
"galleryBanner": {
|
||||
"color": "#FFFFFF",
|
||||
"theme": "light"
|
||||
},
|
||||
"icon": "resources/xml.png",
|
||||
"homepage": "https://github.com/DotJoshJohnson/vscode-xml",
|
||||
"icon": "resources/basex.png",
|
||||
"homepage": "https://github.com/Quodatum/vscode-basex",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DotJoshJohnson/vscode-xml.git"
|
||||
"url": "git+https://github.com/Quodatum/vscode-basex.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/DotJoshJohnson/vscode-xml/issues"
|
||||
"url": "https://github.com/Quodatum/vscode-basex/issues"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.63.0"
|
||||
"vscode": "^1.73.0"
|
||||
},
|
||||
"categories": [
|
||||
"Formatters",
|
||||
"Programming Languages",
|
||||
"Linters",
|
||||
"Snippets",
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:xmlTools.evaluateXPath",
|
||||
"onCommand:xmlTools.executeXQuery",
|
||||
"onCommand:xmlTools.formatAsXml",
|
||||
"onCommand:xmlTools.textToXml",
|
||||
"onCommand:xmlTools.xmlToText",
|
||||
"onCommand:xmlTools.minifyXml",
|
||||
"onCommand:basexTools.evaluateXPath",
|
||||
"onCommand:basexTools.executeXQuery",
|
||||
"onCommand:basexTools.formatAsXml",
|
||||
"onCommand:basexTools.textToXml",
|
||||
"onCommand:basexTools.xmlToText",
|
||||
"onCommand:basexTools.minifyXml",
|
||||
"onCommand:basexTools.xqLintReport",
|
||||
"onLanguage:xml",
|
||||
"onLanguage:xquery",
|
||||
"onLanguage:xsl"
|
||||
],
|
||||
"main": "./out/extension",
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "xmlTools.evaluateXPath",
|
||||
"title": "XML Tools: Evaluate XPath"
|
||||
"command": "basexTools.evaluateXPath",
|
||||
"title": "BaseX Tools: Evaluate XPath"
|
||||
},
|
||||
{
|
||||
"command": "xmlTools.executeXQuery",
|
||||
"title": "XML Tools: Execute XQuery"
|
||||
"command": "basexTools.executeXQuery",
|
||||
"title": "BaseX Tools: Execute XQuery"
|
||||
},
|
||||
{
|
||||
"command": "xmlTools.formatAsXml",
|
||||
"title": "XML Tools: Format as XML"
|
||||
"command": "basexTools.formatAsXml",
|
||||
"title": "BaseX Tools: Format as XML"
|
||||
},
|
||||
{
|
||||
"command": "xmlTools.textToXml",
|
||||
"title": "XML Tools: Convert text to XML (<> -> <>)"
|
||||
"command": "basexTools.textToXml",
|
||||
"title": "BaseX Tools: Convert text to XML (<> -> <>)"
|
||||
},
|
||||
{
|
||||
"command": "xmlTools.xmlToText",
|
||||
"title": "XML Tools: Convert XML to text (<> -> <>)"
|
||||
"command": "basexTools.xmlToText",
|
||||
"title": "BaseX Tools: Convert XML to text (<> -> <>)"
|
||||
},
|
||||
{
|
||||
"command": "xmlTools.getCurrentXPath",
|
||||
"title": "XML Tools: Get Current XPath"
|
||||
"command": "basexTools.getCurrentXPath",
|
||||
"title": "BaseX Tools: Get Current XPath"
|
||||
},
|
||||
{
|
||||
"command": "xmlTools.minifyXml",
|
||||
"title": "XML Tools: Minify XML"
|
||||
"command": "basexTools.minifyXml",
|
||||
"title": "BaseX Tools: Minify XML"
|
||||
},
|
||||
{
|
||||
"command": "basexTools.xqLintReport",
|
||||
"title": "BaseX Tools: Analysis of current location in Xquery source"
|
||||
}
|
||||
],
|
||||
"configuration": {
|
||||
"title": "XML Tools Configuration",
|
||||
"type": "object",
|
||||
"configuration": [
|
||||
{
|
||||
"id": "xmltree",
|
||||
"title": "XML tree view ",
|
||||
"properties": {
|
||||
"xmlTools.enableXmlTreeView": {
|
||||
"basexTools.xmlTree.enableTreeView": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"default": false,
|
||||
"description": "Enables the XML Document view in the explorer for XML documents.",
|
||||
"scope": "window"
|
||||
},
|
||||
"xmlTools.enableXmlTreeViewMetadata": {
|
||||
"basexTools.xmlTree.enableViewMetadata": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Enables attribute and child element counts in the XML Document view.",
|
||||
"scope": "window"
|
||||
},
|
||||
"xmlTools.enableXmlTreeViewCursorSync": {
|
||||
"basexTools.xmlTree.enableViewCursorSync": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.",
|
||||
"scope": "window"
|
||||
}
|
||||
}
|
||||
},
|
||||
"xmlTools.enforcePrettySelfClosingTagOnFormat": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Enforces a space before the forward slash at the end of a self-closing XML tag.",
|
||||
"scope": "resource"
|
||||
},
|
||||
"xmlTools.ignoreDefaultNamespace": {
|
||||
{
|
||||
"id": "xpath",
|
||||
"title": "XPath ",
|
||||
"properties": {
|
||||
"basexTools.xpath.ignoreDefaultNamespace": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Ignore default xmlns attributes when evaluating XPath.",
|
||||
"scope": "window"
|
||||
},
|
||||
"xmlTools.persistXPathQuery": {
|
||||
"basexTools.xpath.persistXPathQuery": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Remember the last XPath query used.",
|
||||
"scope": "window"
|
||||
}
|
||||
}
|
||||
},
|
||||
"xmlTools.removeCommentsOnMinify": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Remove XML comments during minification.",
|
||||
"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": {
|
||||
{
|
||||
"id": "xquery",
|
||||
"title": "XQuery ",
|
||||
"properties": {
|
||||
"basexTools.xquery.executionArguments": {
|
||||
"type": "array",
|
||||
"default": [
|
||||
"-xquery",
|
||||
|
|
@ -156,19 +138,19 @@
|
|||
"description": "Arguments to be passed to the XQuery execution engine.",
|
||||
"scope": "window"
|
||||
},
|
||||
"xmlTools.xqueryExecutionEngine": {
|
||||
"basexTools.xquery.executionEngine": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "The full path to the executable to run when executing XQuery scripts.",
|
||||
"scope": "window"
|
||||
},
|
||||
"xmlTools.xqueryExecutionInputLimit": {
|
||||
"basexTools.xquery.executionInputLimit": {
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"description": "The maximum number of input files to enumerate when executing XQuery scripts.",
|
||||
"scope": "window"
|
||||
},
|
||||
"xmlTools.xqueryExecutionInputSearchPattern": {
|
||||
"basexTools.xquery.executionInputSearchPattern": {
|
||||
"type": "string",
|
||||
"default": "**/*.xml",
|
||||
"description": "The pattern used to search for input XML files when executing XQuery scripts.",
|
||||
|
|
@ -176,6 +158,47 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"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": [
|
||||
{
|
||||
"language": "xquery",
|
||||
|
|
@ -183,14 +206,20 @@
|
|||
"scopeName": "source.xquery"
|
||||
}
|
||||
],
|
||||
"snippets": [
|
||||
{
|
||||
"language": "xquery",
|
||||
"path": "./snippets.jsonc"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
{
|
||||
"key": "ctrl+shift+alt+x",
|
||||
"command": "xmlTools.evaluateXPath"
|
||||
"command": "basexTools.evaluateXPath"
|
||||
},
|
||||
{
|
||||
"key": "ctrl+shift+alt+b",
|
||||
"command": "xmlTools.formatAsXml"
|
||||
"command": "basexTools.formatAsXml"
|
||||
}
|
||||
],
|
||||
"languages": [
|
||||
|
|
@ -203,7 +232,8 @@
|
|||
".xsd",
|
||||
".xsl",
|
||||
".plist",
|
||||
".mobileconfig"
|
||||
".mobileconfig",
|
||||
".sch"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -225,25 +255,25 @@
|
|||
"menus": {
|
||||
"commandPalette": [
|
||||
{
|
||||
"command": "xmlTools.evaluateXPath",
|
||||
"command": "basexTools.evaluateXPath",
|
||||
"when": "editorLangId == xml"
|
||||
},
|
||||
{
|
||||
"command": "xmlTools.executeXQuery",
|
||||
"command": "basexTools.executeXQuery",
|
||||
"when": "editorLangId == xquery"
|
||||
},
|
||||
{
|
||||
"command": "xmlTools.getCurrentXPath",
|
||||
"command": "basexTools.getCurrentXPath",
|
||||
"when": "editorLangId == xml"
|
||||
},
|
||||
{
|
||||
"command": "xmlTools.minifyXml",
|
||||
"command": "basexTools.minifyXml",
|
||||
"when": "editorLangId == xml"
|
||||
}
|
||||
],
|
||||
"editor/context": [
|
||||
{
|
||||
"command": "xmlTools.minifyXml",
|
||||
"command": "basexTools.minifyXml",
|
||||
"group": "1_modification@100",
|
||||
"when": "editorLangId == 'xml'"
|
||||
}
|
||||
|
|
@ -260,7 +290,11 @@
|
|||
}
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"vscode:prepublish": "npm run esbuild-base -- --minify",
|
||||
"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 ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "npm run compile && npm run lint",
|
||||
|
|
@ -268,22 +302,23 @@
|
|||
"test": "node ./out/test/runTest.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/vscode": "^1.63.0",
|
||||
"@types/glob": "^7.2.0",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@types/node": "14.x",
|
||||
"@typescript-eslint/eslint-plugin": "^5.9.1",
|
||||
"@typescript-eslint/parser": "^5.9.1",
|
||||
"@types/xmldom": "^0.1.13",
|
||||
"eslint": "^8.6.0",
|
||||
"@types/node": "^14.18.12",
|
||||
"@types/vscode": "^1.73.0",
|
||||
"@types/xmldom": "^0.1.31",
|
||||
"@typescript-eslint/eslint-plugin": "^5.13.0",
|
||||
"@typescript-eslint/parser": "^5.13.0",
|
||||
"@vscode/test-electron": "^2.1.3",
|
||||
"esbuild": "^0.14.25",
|
||||
"eslint": "^8.10.0",
|
||||
"glob": "^7.2.0",
|
||||
"mocha": "^9.1.3",
|
||||
"typescript": "^4.5.4",
|
||||
"@vscode/test-electron": "^2.0.3"
|
||||
"mocha": "^9.2.1",
|
||||
"typescript": "^4.7.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"xmldom": "^0.1.27",
|
||||
"xpath": "0.0.27",
|
||||
"xqlint": "^0.4.1"
|
||||
"@quodatum/xqlint": "^0.2.0",
|
||||
"@xmldom/xmldom": "^0.8.1",
|
||||
"xpath": "0.0.32"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
BIN
resources/basex.png
Normal file
BIN
resources/basex.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.2 KiB |
13
scripts/test.js
Normal file
13
scripts/test.js
Normal 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);
|
||||
120
snippets.jsonc
Normal file
120
snippets.jsonc
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
{
|
||||
|
||||
"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}
|
||||
|
||||
46
src/@quodatum/xqlint.d.ts
vendored
Normal file
46
src/@quodatum/xqlint.d.ts
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
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;
|
||||
|
||||
}
|
||||
|
|
@ -1,26 +1,26 @@
|
|||
import { workspace, Uri } from "vscode";
|
||||
|
||||
const ExtensionTopLevelSection = "xmlTools";
|
||||
const ExtensionTopLevelSection = "basexTools";
|
||||
|
||||
export class Configuration {
|
||||
static get enableXmlTreeView(): boolean {
|
||||
return this._getForWindow<boolean>("enableXmlTreeView");
|
||||
return this._getForWindow<boolean>("xmlTree.enableTreeView");
|
||||
}
|
||||
|
||||
static get enableXmlTreeViewMetadata(): boolean {
|
||||
return this._getForWindow<boolean>("enableXmlTreeViewMetadata");
|
||||
return this._getForWindow<boolean>("xmlTree.enableViewMetadata");
|
||||
}
|
||||
|
||||
static get enableXmlTreeViewCursorSync(): boolean {
|
||||
return this._getForWindow<boolean>("enableXmlTreeViewCursorSync");
|
||||
return this._getForWindow<boolean>("xmlTree.enableViewCursorSync");
|
||||
}
|
||||
|
||||
static get ignoreDefaultNamespace(): boolean {
|
||||
return this._getForWindow<boolean>("ignoreDefaultNamespace");
|
||||
return this._getForWindow<boolean>("xpath.ignoreDefaultNamespace");
|
||||
}
|
||||
|
||||
static get persistXPathQuery(): boolean {
|
||||
return this._getForWindow<boolean>("persistXPathQuery");
|
||||
return this._getForWindow<boolean>("xpath.persistXPathQuery");
|
||||
}
|
||||
|
||||
static get xmlFormatterImplementation(): string {
|
||||
|
|
@ -28,19 +28,19 @@ export class Configuration {
|
|||
}
|
||||
|
||||
static get xqueryExecutionArguments(): string[] {
|
||||
return this._getForWindow<string[]>("xqueryExecutionArguments");
|
||||
return this._getForWindow<string[]>("xquery.executionArguments");
|
||||
}
|
||||
|
||||
static get xqueryExecutionEngine(): string {
|
||||
return this._getForWindow<string>("xqueryExecutionEngine");
|
||||
return this._getForWindow<string>("xquery.executionEngine");
|
||||
}
|
||||
|
||||
static get xqueryExecutionInputLimit(): number {
|
||||
return this._getForWindow<number>("xqueryExecutionInputLimit");
|
||||
return this._getForWindow<number>("xquery.executionInputLimit");
|
||||
}
|
||||
|
||||
static get xqueryExecutionInputSearchPattern(): string {
|
||||
return this._getForWindow<string>("xqueryExecutionInputSearchPattern");
|
||||
return this._getForWindow<string>("xquery.executionInputSearchPattern");
|
||||
}
|
||||
|
||||
static enforcePrettySelfClosingTagOnFormat(resource: Uri): boolean {
|
||||
|
|
|
|||
|
|
@ -3,3 +3,4 @@ export * from "./create-document-selector";
|
|||
export * from "./extension-state";
|
||||
export * from "./native-commands";
|
||||
export * from "./xml-traverser";
|
||||
export * from "./logger";
|
||||
|
|
|
|||
44
src/common/logger.ts
Normal file
44
src/common/logger.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// 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
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { CompletionItem, CompletionItemKind, CompletionItemProvider, Position, TextDocument } from "vscode";
|
||||
import { XQLint} from "@quodatum/xqlint";
|
||||
|
||||
const XQLint = require("xqlint").XQLint;
|
||||
|
||||
export class XQueryCompletionItemProvider implements CompletionItemProvider {
|
||||
|
||||
|
|
@ -24,7 +24,9 @@ export class XQueryCompletionItemProvider implements CompletionItemProvider {
|
|||
case "function":
|
||||
completionItem.kind = CompletionItemKind.Function;
|
||||
|
||||
// eslint-disable-next-line no-case-declarations
|
||||
const funcStart = (xqLintCompletionItem.value.indexOf(":") + 1);
|
||||
// eslint-disable-next-line no-case-declarations
|
||||
const funcEnd = xqLintCompletionItem.value.indexOf("(");
|
||||
|
||||
completionItem.insertText = xqLintCompletionItem.value.substring(funcStart, funcEnd);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
export namespace commands {
|
||||
export const evaluateXPath = "xmlTools.evaluateXPath";
|
||||
export const executeXQuery = "xmlTools.executeXQuery";
|
||||
export const formatAsXml = "xmlTools.formatAsXml";
|
||||
export const xmlToText = "xmlTools.xmlToText";
|
||||
export const textToXml = "xmlTools.textToXml";
|
||||
export const getCurrentXPath = "xmlTools.getCurrentXPath";
|
||||
export const minifyXml = "xmlTools.minifyXml";
|
||||
export const evaluateXPath = "basexTools.evaluateXPath";
|
||||
export const executeXQuery = "basexTools.executeXQuery";
|
||||
export const formatAsXml = "basexTools.formatAsXml";
|
||||
export const xmlToText = "basexTools.xmlToText";
|
||||
export const textToXml = "basexTools.textToXml";
|
||||
export const getCurrentXPath = "basexTools.getCurrentXPath";
|
||||
export const minifyXml = "basexTools.minifyXml";
|
||||
export const xqLintReport = "basexTools.xqLintReport";
|
||||
}
|
||||
|
||||
export namespace contextKeys {
|
||||
|
|
|
|||
|
|
@ -1,22 +1,27 @@
|
|||
import {
|
||||
commands, languages, window, workspace, ExtensionContext, Memento,
|
||||
commands, languages, window, ExtensionContext,
|
||||
TextEditor, TextEditorSelectionChangeEvent, TextEditorSelectionChangeKind, DiagnosticCollection
|
||||
} from "vscode";
|
||||
import { channel } from "./common/logger";
|
||||
|
||||
import { createDocumentSelector, ExtensionState, Configuration } from "./common";
|
||||
import { XQueryCompletionItemProvider } from "./completion";
|
||||
import { XmlFormatterFactory, XmlFormattingEditProvider } from "./formatting";
|
||||
import { formatAsXml, minifyXml, xmlToText, textToXml } from "./formatting/commands";
|
||||
import { XQueryLinter } from "./linting";
|
||||
import { XQueryLinter,xqLintReport } from "./linting";
|
||||
import { XmlTreeDataProvider } from "./tree-view";
|
||||
import { evaluateXPath, getCurrentXPath } from "./xpath/commands";
|
||||
import { executeXQuery } from "./xquery-execution/commands";
|
||||
|
||||
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;
|
||||
|
||||
export function activate(context: ExtensionContext) {
|
||||
channel.log("Extension activate");
|
||||
ExtensionState.configure(context);
|
||||
|
||||
const xmlXsdDocSelector = [...createDocumentSelector(constants.languageIds.xml), ...createDocumentSelector(constants.languageIds.xsd)];
|
||||
|
|
@ -29,16 +34,30 @@ export function activate(context: ExtensionContext) {
|
|||
|
||||
/* Formatting Features */
|
||||
const xmlFormattingEditProvider = new XmlFormattingEditProvider(XmlFormatterFactory.getXmlFormatter());
|
||||
|
||||
const xqueryFormattingEditProvider = new XQueryFormatter();
|
||||
context.subscriptions.push(
|
||||
commands.registerTextEditorCommand(constants.commands.formatAsXml, formatAsXml),
|
||||
commands.registerTextEditorCommand(constants.commands.xmlToText, xmlToText),
|
||||
commands.registerTextEditorCommand(constants.commands.textToXml, textToXml),
|
||||
commands.registerTextEditorCommand(constants.commands.minifyXml, minifyXml),
|
||||
commands.registerTextEditorCommand(constants.commands.xqLintReport, xqLintReport),
|
||||
|
||||
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 */
|
||||
diagnosticCollectionXQuery = languages.createDiagnosticCollection(constants.diagnosticCollections.xquery);
|
||||
context.subscriptions.push(
|
||||
|
|
@ -75,13 +94,13 @@ 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];
|
||||
|
||||
|
|
|
|||
|
|
@ -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,4 +1,5 @@
|
|||
export * from "./formatAsXml";
|
||||
export * from "./minifyXml";
|
||||
export * from "./xmlToText";
|
||||
export * from "./textToXml";
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
import { workspace } from "vscode";
|
||||
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
|
||||
import { Range, TextEditor, TextEditorEdit } 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 minifyXml(editor: TextEditor, edit: TextEditorEdit): void {
|
||||
|
|
|
|||
|
|
@ -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(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/&/g, "&")
|
||||
// tslint:disable-next-line
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'");
|
||||
|
||||
textEdit.replace(selection, transformed);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -1,12 +1,7 @@
|
|||
import { workspace } from "vscode";
|
||||
import { ProviderResult, Range, TextEdit, TextEditor, Selection } from "vscode";
|
||||
|
||||
import { NativeCommands } from "../../common";
|
||||
import * as constants from "../../constants";
|
||||
import { Range, TextEditor, Selection } from "vscode";
|
||||
|
||||
|
||||
import { XmlFormatterFactory } from "../xml-formatter";
|
||||
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
|
||||
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
|
||||
|
||||
export function xmlToText(textEditor: TextEditor): void {
|
||||
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 transformed = txt
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/&/g, "&")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
|
||||
|
|
@ -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(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/&/g, "&")
|
||||
// tslint:disable-next-line
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'");
|
||||
|
||||
textEdit.replace(selection, transformed);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ export class ClassicXmlFormatter implements XmlFormatter {
|
|||
|
||||
if (options.splitXmlnsOnFormat) {
|
||||
xml = xml
|
||||
.replace(/xmlns\:/g, "~::~xmlns:")
|
||||
.replace(/xmlns\=/g, "~::~xmlns=");
|
||||
.replace(/xmlns:/g, "~::~xmlns:")
|
||||
.replace(/xmlns=/g, "~::~xmlns=");
|
||||
}
|
||||
|
||||
const parts: string[] = xml.split("~::~");
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
export * from "./xml-formatter";
|
||||
export * from "./xml-formatting-edit-provider";
|
||||
export * from "./xml-formatting-options";
|
||||
export * from "./xquery-formatting-provider";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { window, workspace } from "vscode";
|
||||
|
||||
import { Configuration, ExtensionState } from "../common";
|
||||
|
||||
import { Configuration } from "../common";
|
||||
import * as constants from "../constants";
|
||||
import { ClassicXmlFormatter } from "./formatters/classic-xml-formatter";
|
||||
import { V2XmlFormatter } from "./formatters/v2-xml-formatter";
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { EndOfLine, FormattingOptions, TextDocument } from "vscode";
|
||||
|
||||
import { Configuration } from "../common";
|
||||
import * as constants from "../constants";
|
||||
|
||||
export interface XmlFormattingOptions {
|
||||
editorOptions: FormattingOptions;
|
||||
|
|
|
|||
33
src/formatting/xquery-formatting-provider.ts
Normal file
33
src/formatting/xquery-formatting-provider.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* 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)];
|
||||
}
|
||||
}
|
||||
28
src/hover/hover.ts
Normal file
28
src/hover/hover.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// 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
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1,2 @@
|
|||
export * from "./xquery-linter";
|
||||
export * from "./report";
|
||||
|
|
|
|||
19
src/linting/report.ts
Normal file
19
src/linting/report.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { Diagnostic, DiagnosticSeverity, Position, Range } from "vscode";
|
||||
import { XQLint} from "@quodatum/xqlint";
|
||||
|
||||
const XQLint = require("xqlint").XQLint;
|
||||
|
||||
export class XQueryLinter {
|
||||
static SEVERITY_WARNING = 1;
|
||||
|
|
|
|||
59
src/symbols/symbols.ts
Normal file
59
src/symbols/symbols.ts
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* 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;
|
||||
};
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const child_process = require("child_process");
|
||||
import child_process = require("child_process");
|
||||
|
||||
export class ChildProcess {
|
||||
static async spawn(executable: string, args: string[]): Promise<void> {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue