Compare commits

...

26 commits

Author SHA1 Message Date
6e5d06b871 [mod] tidy 2023-02-20 10:17:47 +00:00
8d47e56dfa [mod] use xqlint 0.2.0 2023-02-19 18:07:31 +00:00
497f7bb526 [mod] update xqlint 2023-02-09 11:45:55 +00:00
b2f40425e3 [add] basexTools.xqLintReport 2023-02-09 09:51:54 +00:00
2b717e39e6 [mod] tidy 65 snapshot 2023-01-28 21:05:06 +00:00
6d074b29c9 [mod] v0.0.64 2023-01-26 11:32:14 +00:00
52237c8267 [mod] v0.0.63 2022-10-06 11:42:28 +01:00
0541ecfcad [MOD] 0.0.58 2022-10-05 12:37:26 +01:00
484710a1b2 [mod] symbols 2022-09-25 12:07:41 +01:00
apb
5bc83682a5 [mod] build 0.0.53 2022-09-21 18:05:32 +01:00
apb
b3f47dc553 [fix] typescript 2022-06-12 16:20:17 +01:00
a0b3d96f38 Merge pull request 'vscode-basex' (#9) from vscode-basex into master
Reviewed-on: #9
2022-06-07 17:44:25 +01:00
80d5ceea19 Merge branch 'master' into vscode-basex 2022-06-07 17:44:12 +01:00
47baf6f2b9 [mod] release 0.5.2 2022-06-07 16:29:12 +01:00
cfc8ba3817 [fix] #6 #3 2022-03-07 16:37:26 +00:00
475943053c Merge branch 'vscode-basex' of https://git.quodatum.duckdns.org/apb/vscode-basex into vscode-basex 2022-03-06 23:47:05 +00:00
e945532956 [mod] symbols 2022-03-06 23:46:59 +00:00
19b4f84ce5 Merge pull request '[mod] ver:0.0.28' (#4) from vscode-basex into master
Reviewed-on: #4
2022-02-20 19:07:56 +00:00
280547a741 Merge branch 'master' into vscode-basex 2022-02-20 19:07:12 +00:00
9dd58b2b70 [mod] ver:0.0.28 2022-02-20 18:57:48 +00:00
ee6e911216 Merge pull request 'vscode-basex' (#1) from vscode-basex into master
Reviewed-on: #1
2022-02-09 22:38:59 +00:00
560628c7de [mod] use esbuild 2022-02-06 12:51:13 +00:00
a208e502ea [add] treat schematron (.sch) as XML 2022-02-05 23:26:27 +00:00
c275d88f77 [mod] xmlTools ->basexTools 2022-02-05 22:40:34 +00:00
4cbf4cb568 [add] icon 2022-01-31 21:15:37 +00:00
6f919dd209 [add] icon 2022-01-31 21:14:34 +00:00
46 changed files with 5891 additions and 3019 deletions

20
.eslintrc.json Normal file
View file

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

View file

@ -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
View file

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

5
.vscode/extensions.json vendored Normal file
View file

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

3
.vscode/launch.json vendored
View file

@ -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
View file

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

View file

@ -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

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -1,43 +1,55 @@
# 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)
# BaseX Tools for Visual Studio Code
[![](https://img.shields.io/badge/TWITTER-%40DotJohnson-blue.svg?logo=twitter&style=for-the-badge)](https://twitter.com/DotJoshJohnson)
[![](https://img.shields.io/badge/gitter-join_chat-1dce73.svg?style=for-the-badge&logo=gitter-white)](https://gitter.im/vscode-xml/vscode-xml)
[![Beerpay](https://img.shields.io/beerpay/DotJoshJohnson/vscode-xml.svg?style=for-the-badge)](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

View file

@ -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

View file

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

57
notes.md Normal file
View file

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

7479
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,289 +1,324 @@
{
"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,
"publisher": "quodatum",
"author": {
"name": "Andy Bunce",
"url": "https://github.com/DotJoshJohnson"
},
"license": "MIT",
"galleryBanner": {
"color": "#FFFFFF",
"theme": "light"
},
"icon": "resources/xml.png",
"homepage": "https://github.com/DotJoshJohnson/vscode-xml",
"repository": {
"type": "git",
"url": "https://github.com/DotJoshJohnson/vscode-xml.git"
},
"bugs": {
"url": "https://github.com/DotJoshJohnson/vscode-xml/issues"
},
"engines": {
"vscode": "^1.63.0"
},
"categories": [
"Formatters",
"Programming Languages",
"Linters",
"Other"
"name": "vscode-basex",
"displayName": "BaseX tools",
"description": "BaseX tools: XQuery, XML, XPath Tools for Visual Studio Code",
"version": "0.1.0",
"preview": true,
"publisher": "quodatum",
"author": "Andy Bunce (https://github.com/Quodatum)",
"license": "MIT",
"galleryBanner": {
"color": "#FFFFFF",
"theme": "light"
},
"icon": "resources/basex.png",
"homepage": "https://github.com/Quodatum/vscode-basex",
"repository": {
"type": "git",
"url": "git+https://github.com/Quodatum/vscode-basex.git"
},
"bugs": {
"url": "https://github.com/Quodatum/vscode-basex/issues"
},
"engines": {
"vscode": "^1.73.0"
},
"categories": [
"Formatters",
"Programming Languages",
"Linters",
"Snippets",
"Other"
],
"activationEvents": [
"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.js",
"contributes": {
"commands": [
{
"command": "basexTools.evaluateXPath",
"title": "BaseX Tools: Evaluate XPath"
},
{
"command": "basexTools.executeXQuery",
"title": "BaseX Tools: Execute XQuery"
},
{
"command": "basexTools.formatAsXml",
"title": "BaseX Tools: Format as XML"
},
{
"command": "basexTools.textToXml",
"title": "BaseX Tools: Convert text to XML (&lt;&gt; -> <>)"
},
{
"command": "basexTools.xmlToText",
"title": "BaseX Tools: Convert XML to text (<> -> &lt;&gt;)"
},
{
"command": "basexTools.getCurrentXPath",
"title": "BaseX Tools: Get Current XPath"
},
{
"command": "basexTools.minifyXml",
"title": "BaseX Tools: Minify XML"
},
{
"command": "basexTools.xqLintReport",
"title": "BaseX Tools: Analysis of current location in Xquery source"
}
],
"activationEvents": [
"onCommand:xmlTools.evaluateXPath",
"onCommand:xmlTools.executeXQuery",
"onCommand:xmlTools.formatAsXml",
"onCommand:xmlTools.textToXml",
"onCommand:xmlTools.xmlToText",
"onCommand:xmlTools.minifyXml",
"onLanguage:xml",
"onLanguage:xquery",
"onLanguage:xsl"
],
"main": "./out/extension",
"contributes": {
"commands": [
{
"command": "xmlTools.evaluateXPath",
"title": "XML Tools: Evaluate XPath"
},
{
"command": "xmlTools.executeXQuery",
"title": "XML Tools: Execute XQuery"
},
{
"command": "xmlTools.formatAsXml",
"title": "XML Tools: Format as XML"
},
{
"command": "xmlTools.textToXml",
"title": "XML Tools: Convert text to XML (&lt;&gt; -> <>)"
},
{
"command": "xmlTools.xmlToText",
"title": "XML Tools: Convert XML to text (<> -> &lt;&gt;)"
},
{
"command": "xmlTools.getCurrentXPath",
"title": "XML Tools: Get Current XPath"
},
{
"command": "xmlTools.minifyXml",
"title": "XML Tools: Minify XML"
}
],
"configuration": {
"title": "XML Tools Configuration",
"type": "object",
"properties": {
"xmlTools.enableXmlTreeView": {
"type": "boolean",
"default": true,
"description": "Enables the XML Document view in the explorer for XML documents.",
"scope": "window"
},
"xmlTools.enableXmlTreeViewMetadata": {
"type": "boolean",
"default": true,
"description": "Enables attribute and child element counts in the XML Document view.",
"scope": "window"
},
"xmlTools.enableXmlTreeViewCursorSync": {
"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": {
"type": "boolean",
"default": true,
"description": "Ignore default xmlns attributes when evaluating XPath.",
"scope": "window"
},
"xmlTools.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": {
"type": "array",
"default": [
"-xquery",
"$(script)",
"-in",
"$(input)",
"-out",
"$(input).output.xml"
],
"description": "Arguments to be passed to the XQuery execution engine.",
"scope": "window"
},
"xmlTools.xqueryExecutionEngine": {
"type": "string",
"default": "",
"description": "The full path to the executable to run when executing XQuery scripts.",
"scope": "window"
},
"xmlTools.xqueryExecutionInputLimit": {
"type": "integer",
"default": 100,
"description": "The maximum number of input files to enumerate when executing XQuery scripts.",
"scope": "window"
},
"xmlTools.xqueryExecutionInputSearchPattern": {
"type": "string",
"default": "**/*.xml",
"description": "The pattern used to search for input XML files when executing XQuery scripts.",
"scope": "window"
}
}
},
"grammars": [
{
"language": "xquery",
"path": "./languages/xquery/xquery.tmLanguage",
"scopeName": "source.xquery"
}
],
"keybindings": [
{
"key": "ctrl+shift+alt+x",
"command": "xmlTools.evaluateXPath"
},
{
"key": "ctrl+shift+alt+b",
"command": "xmlTools.formatAsXml"
}
],
"languages": [
{
"id": "xml",
"extensions": [
".config",
".csproj",
".xml",
".xsd",
".xsl",
".plist",
".mobileconfig"
]
},
{
"id": "xquery",
"aliases": [
"XQuery",
"xquery"
],
"extensions": [
".xq",
".xql",
".xqm",
".xqy",
".xquery"
],
"configuration": "./languages/xquery/xquery.json"
}
],
"menus": {
"commandPalette": [
{
"command": "xmlTools.evaluateXPath",
"when": "editorLangId == xml"
},
{
"command": "xmlTools.executeXQuery",
"when": "editorLangId == xquery"
},
{
"command": "xmlTools.getCurrentXPath",
"when": "editorLangId == xml"
},
{
"command": "xmlTools.minifyXml",
"when": "editorLangId == xml"
}
],
"editor/context": [
{
"command": "xmlTools.minifyXml",
"group": "1_modification@100",
"when": "editorLangId == 'xml'"
}
]
},
"views": {
"explorer": [
{
"id": "xmlTreeView",
"name": "XML Document",
"when": "xmlTreeViewEnabled"
}
]
"configuration": [
{
"id": "xmltree",
"title": "XML tree view ",
"properties": {
"basexTools.xmlTree.enableTreeView": {
"type": "boolean",
"default": false,
"description": "Enables the XML Document view in the explorer for XML documents.",
"scope": "window"
},
"basexTools.xmlTree.enableViewMetadata": {
"type": "boolean",
"default": true,
"description": "Enables attribute and child element counts in the XML Document view.",
"scope": "window"
},
"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"
}
}
},
{
"id": "xpath",
"title": "XPath ",
"properties": {
"basexTools.xpath.ignoreDefaultNamespace": {
"type": "boolean",
"default": true,
"description": "Ignore default xmlns attributes when evaluating XPath.",
"scope": "window"
},
"basexTools.xpath.persistXPathQuery": {
"type": "boolean",
"default": true,
"description": "Remember the last XPath query used.",
"scope": "window"
}
}
},
{
"id": "xquery",
"title": "XQuery ",
"properties": {
"basexTools.xquery.executionArguments": {
"type": "array",
"default": [
"-xquery",
"$(script)",
"-in",
"$(input)",
"-out",
"$(input).output.xml"
],
"description": "Arguments to be passed to the XQuery execution engine.",
"scope": "window"
},
"basexTools.xquery.executionEngine": {
"type": "string",
"default": "",
"description": "The full path to the executable to run when executing XQuery scripts.",
"scope": "window"
},
"basexTools.xquery.executionInputLimit": {
"type": "integer",
"default": 100,
"description": "The maximum number of input files to enumerate when executing XQuery scripts.",
"scope": "window"
},
"basexTools.xquery.executionInputSearchPattern": {
"type": "string",
"default": "**/*.xml",
"description": "The pattern used to search for input XML files when executing XQuery scripts.",
"scope": "window"
}
}
},
{
"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",
"path": "./languages/xquery/xquery.tmLanguage",
"scopeName": "source.xquery"
}
],
"snippets": [
{
"language": "xquery",
"path": "./snippets.jsonc"
}
],
"keybindings": [
{
"key": "ctrl+shift+alt+x",
"command": "basexTools.evaluateXPath"
},
{
"key": "ctrl+shift+alt+b",
"command": "basexTools.formatAsXml"
}
],
"languages": [
{
"id": "xml",
"extensions": [
".config",
".csproj",
".xml",
".xsd",
".xsl",
".plist",
".mobileconfig",
".sch"
]
},
{
"id": "xquery",
"aliases": [
"XQuery",
"xquery"
],
"extensions": [
".xq",
".xql",
".xqm",
".xqy",
".xquery"
],
"configuration": "./languages/xquery/xquery.json"
}
],
"menus": {
"commandPalette": [
{
"command": "basexTools.evaluateXPath",
"when": "editorLangId == xml"
},
{
"command": "basexTools.executeXQuery",
"when": "editorLangId == xquery"
},
{
"command": "basexTools.getCurrentXPath",
"when": "editorLangId == xml"
},
{
"command": "basexTools.minifyXml",
"when": "editorLangId == xml"
}
],
"editor/context": [
{
"command": "basexTools.minifyXml",
"group": "1_modification@100",
"when": "editorLangId == 'xml'"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"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",
"glob": "^7.2.0",
"mocha": "^9.1.3",
"typescript": "^4.5.4",
"@vscode/test-electron": "^2.0.3"
},
"dependencies": {
"xmldom": "^0.1.27",
"xpath": "0.0.27",
"xqlint": "^0.4.1"
"views": {
"explorer": [
{
"id": "xmlTreeView",
"name": "XML Document",
"when": "xmlTreeViewEnabled"
}
]
}
},
"scripts": {
"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",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/mocha": "^9.0.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.2.1",
"typescript": "^4.7.3"
},
"dependencies": {
"@quodatum/xqlint": "^0.2.0",
"@xmldom/xmldom": "^0.8.1",
"xpath": "0.0.32"
}
}

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
View file

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

120
snippets.jsonc Normal file
View 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
View 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;
}

View file

@ -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 {

View file

@ -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
View 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

View file

@ -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);

View file

@ -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 {

View file

@ -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 { formatAsXml, minifyXml, xmlToText, textToXml } from "./formatting/commands";
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];

View file

@ -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());

View file

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

View file

@ -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 {

View file

@ -1,33 +0,0 @@
import { workspace } from "vscode";
import { ProviderResult, Range, TextEdit, TextEditor, Selection } from "vscode";
import { NativeCommands } from "../../common";
import * as constants from "../../constants";
import { XmlFormatterFactory } from "../xml-formatter";
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
export function textToXml(textEditor: TextEditor): void {
textEditor.edit(textEdit => {
const selections = textEditor.selections;
selections.forEach(selection => {
if (selection.isEmpty) {
selection = new Selection(
textEditor.document.positionAt(0),
textEditor.document.positionAt(textEditor.document.getText().length)
);
}
const txt = textEditor.document.getText(new Range(selection.start, selection.end));
const transformed = txt
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&amp;/g, "&")
// tslint:disable-next-line
.replace(/&quot;/g, '"')
.replace(/&apos;/g, "'");
textEdit.replace(selection, transformed);
});
});
}

View file

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

View file

@ -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("~::~");

View file

@ -1,3 +1,4 @@
export * from "./xml-formatter";
export * from "./xml-formatting-edit-provider";
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 { ClassicXmlFormatter } from "./formatters/classic-xml-formatter";
import { V2XmlFormatter } from "./formatters/v2-xml-formatter";

View file

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

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

View file

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

19
src/linting/report.ts Normal file
View 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);
});
});
}

View file

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

View file

@ -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);
}
}

View file

@ -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";

View file

@ -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;

View file

@ -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> {