Compare commits
12 commits
vscode-bas
...
master
Author | SHA1 | Date | |
---|---|---|---|
6e5d06b871 | |||
8d47e56dfa | |||
497f7bb526 | |||
b2f40425e3 | |||
2b717e39e6 | |||
6d074b29c9 | |||
52237c8267 | |||
0541ecfcad | |||
484710a1b2 | |||
5bc83682a5 | |||
b3f47dc553 | |||
a0b3d96f38 |
23 changed files with 5179 additions and 2582 deletions
.vscodeignoreCHANGELOG.mdCONTRIBUTING.mdREADME.mdazure-pipelines.yml
languages/xquery
package-lock.jsonpackage.jsonsrc
|
@ -1,6 +1,7 @@
|
|||
node_modules
|
||||
#out/
|
||||
src/
|
||||
tsconfig.json
|
||||
vsc-extension-quickstart.md
|
||||
.github
|
||||
.gitignore
|
||||
.vscode
|
||||
|
|
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -1,4 +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
|
||||
|
||||
0.0.27 doc format
|
||||
0.0.4 [add] treat schematron (.sch) as XML
|
|
@ -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.
|
51
README.md
51
README.md
|
@ -1,32 +1,55 @@
|
|||
# BaseX Tools for Visual Studio Code
|
||||
This project was originally a fork of https://github.com/DotJoshJohnson/vscode-xml
|
||||
|
||||
This extension adds features to support BaseX development on VSCode.
|
||||
* XQuery 3.1, XQuery update, Full text syntax support
|
||||
* XQuery code format
|
||||
|
||||
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.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
|
||||
|
||||
## Inspiration
|
||||
|
||||
This is a fork of [DotJoshJohnson/vscode-xml](https://github.com/DotJoshJohnson/vscode-xml). DotJoshJohnson did the intial work, but I want to go in a different direction.
|
|
@ -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": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["'", "'"],
|
||||
["\"", "\""],
|
||||
["`", "`"]
|
||||
]
|
||||
}
|
||||
|
|
7361
package-lock.json
generated
7361
package-lock.json
generated
File diff suppressed because it is too large
Load diff
36
package.json
36
package.json
|
@ -2,7 +2,7 @@
|
|||
"name": "vscode-basex",
|
||||
"displayName": "BaseX tools",
|
||||
"description": "BaseX tools: XQuery, XML, XPath Tools for Visual Studio Code",
|
||||
"version": "0.0.52",
|
||||
"version": "0.1.0",
|
||||
"preview": true,
|
||||
"publisher": "quodatum",
|
||||
"author": "Andy Bunce (https://github.com/Quodatum)",
|
||||
|
@ -21,7 +21,7 @@
|
|||
"url": "https://github.com/Quodatum/vscode-basex/issues"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.63.0"
|
||||
"vscode": "^1.73.0"
|
||||
},
|
||||
"categories": [
|
||||
"Formatters",
|
||||
|
@ -37,11 +37,12 @@
|
|||
"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": [
|
||||
{
|
||||
|
@ -73,15 +74,14 @@
|
|||
"title": "BaseX Tools: Minify XML"
|
||||
},
|
||||
{
|
||||
"command": "basexTools.getAST",
|
||||
"title": "BaseX Tools: AST"
|
||||
"command": "basexTools.xqLintReport",
|
||||
"title": "BaseX Tools: Analysis of current location in Xquery source"
|
||||
}
|
||||
],
|
||||
"configuration": [
|
||||
{
|
||||
"id": "xmltree",
|
||||
"title": "XML tree view ",
|
||||
|
||||
"properties": {
|
||||
"basexTools.xmlTree.enableTreeView": {
|
||||
"type": "boolean",
|
||||
|
@ -106,7 +106,7 @@
|
|||
{
|
||||
"id": "xpath",
|
||||
"title": "XPath ",
|
||||
"properties":{
|
||||
"properties": {
|
||||
"basexTools.xpath.ignoreDefaultNamespace": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
|
@ -119,11 +119,12 @@
|
|||
"description": "Remember the last XPath query used.",
|
||||
"scope": "window"
|
||||
}
|
||||
}
|
||||
},{
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "xquery",
|
||||
"title": "XQuery ",
|
||||
"properties":{
|
||||
"properties": {
|
||||
"basexTools.xquery.executionArguments": {
|
||||
"type": "array",
|
||||
"default": [
|
||||
|
@ -156,8 +157,8 @@
|
|||
"scope": "window"
|
||||
}
|
||||
}
|
||||
|
||||
},{
|
||||
},
|
||||
{
|
||||
"title": "BaseX Tools ",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -167,7 +168,6 @@
|
|||
"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,
|
||||
|
@ -196,7 +196,7 @@
|
|||
"description": "Supported XML Formatters: classic",
|
||||
"scope": "window"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"grammars": [
|
||||
|
@ -305,7 +305,7 @@
|
|||
"@types/glob": "^7.2.0",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@types/node": "^14.18.12",
|
||||
"@types/vscode": "^1.63.0",
|
||||
"@types/vscode": "^1.73.0",
|
||||
"@types/xmldom": "^0.1.31",
|
||||
"@typescript-eslint/eslint-plugin": "^5.13.0",
|
||||
"@typescript-eslint/parser": "^5.13.0",
|
||||
|
@ -314,11 +314,11 @@
|
|||
"eslint": "^8.10.0",
|
||||
"glob": "^7.2.0",
|
||||
"mocha": "^9.2.1",
|
||||
"typescript": "^4.6.2"
|
||||
"typescript": "^4.7.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@quodatum/xqlint": "^0.0.11",
|
||||
"@quodatum/xqlint": "^0.2.0",
|
||||
"@xmldom/xmldom": "^0.8.1",
|
||||
"xpath": "0.0.32"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
42
src/@quodatum/xqlint.d.ts
vendored
42
src/@quodatum/xqlint.d.ts
vendored
|
@ -1,6 +1,44 @@
|
|||
|
||||
declare module '@quodatum/xqlint'{
|
||||
export function XQLint(source :string, opts :object) :any;
|
||||
export function XQueryLexer() :any;
|
||||
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,5 +0,0 @@
|
|||
# 0.0.48
|
||||
* Fix xmlToText #6
|
||||
* FIX outline all vars
|
||||
|
||||
# 0.0.47
|
|
@ -8,6 +8,23 @@ 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{
|
||||
|
@ -16,6 +33,9 @@ export class channel {
|
|||
static appendLine(msg: string) :void{
|
||||
_channel.appendLine(msg)
|
||||
}
|
||||
static dir(obj: object) :void{
|
||||
_channel.appendLine(dump(obj))
|
||||
}
|
||||
static show() :void{
|
||||
_channel.show
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { CompletionItem, CompletionItemKind, CompletionItemProvider, Position, TextDocument } from "vscode";
|
||||
import { XQLint} from "@quodatum/xqlint";
|
||||
|
||||
const XQLint = require("@quodatum/xqlint").XQLint;
|
||||
|
||||
export class XQueryCompletionItemProvider implements CompletionItemProvider {
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ export namespace commands {
|
|||
export const textToXml = "basexTools.textToXml";
|
||||
export const getCurrentXPath = "basexTools.getCurrentXPath";
|
||||
export const minifyXml = "basexTools.minifyXml";
|
||||
export const getAST = "basexTools.getAST";
|
||||
export const xqLintReport = "basexTools.xqLintReport";
|
||||
}
|
||||
|
||||
export namespace contextKeys {
|
||||
|
|
|
@ -8,7 +8,7 @@ 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,getAst } from "./linting";
|
||||
import { XQueryLinter,xqLintReport } from "./linting";
|
||||
import { XmlTreeDataProvider } from "./tree-view";
|
||||
import { evaluateXPath, getCurrentXPath } from "./xpath/commands";
|
||||
import { executeXQuery } from "./xquery-execution/commands";
|
||||
|
@ -16,6 +16,7 @@ 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;
|
||||
|
||||
|
@ -39,7 +40,7 @@ export function activate(context: ExtensionContext) {
|
|||
commands.registerTextEditorCommand(constants.commands.xmlToText, xmlToText),
|
||||
commands.registerTextEditorCommand(constants.commands.textToXml, textToXml),
|
||||
commands.registerTextEditorCommand(constants.commands.minifyXml, minifyXml),
|
||||
commands.registerTextEditorCommand(constants.commands.getAST, getAst),
|
||||
commands.registerTextEditorCommand(constants.commands.xqLintReport, xqLintReport),
|
||||
|
||||
languages.registerDocumentFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider),
|
||||
languages.registerDocumentRangeFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider),
|
||||
|
@ -53,6 +54,9 @@ export function activate(context: ExtensionContext) {
|
|||
// 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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,7 +1,6 @@
|
|||
import { EndOfLine, FormattingOptions, TextDocument } from "vscode";
|
||||
|
||||
import { Configuration } from "../common";
|
||||
import * as constants from "../constants";
|
||||
|
||||
export interface XmlFormattingOptions {
|
||||
editorOptions: FormattingOptions;
|
||||
|
|
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,23 +0,0 @@
|
|||
|
||||
import { Range, TextEditor, Selection } from "vscode";
|
||||
import { channel } from "../common/logger";
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const XQLint = require("@quodatum/xqlint").XQLint;
|
||||
|
||||
export function getAst(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 text = textEditor.document.getText(new Range(selection.start, selection.end));
|
||||
const linter = new XQLint(text);
|
||||
const ast=linter.getAST();
|
||||
channel.appendLine(ast);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,2 +1,2 @@
|
|||
export * from "./xquery-linter";
|
||||
export * from "./getAST";
|
||||
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("@quodatum/xqlint").XQLint;
|
||||
|
||||
export class XQueryLinter {
|
||||
static SEVERITY_WARNING = 1;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import { XQLint } from '@quodatum/xqlint';
|
||||
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 Symbols
|
||||
// This class handles XQuery Symbols
|
||||
//
|
||||
function makeSymbol(name: string, description: string, icon: SymbolKind, pos: any) {
|
||||
const spos = new Position(pos.sl, pos.sc);
|
||||
|
@ -14,6 +14,7 @@ function makeSymbol(name: string, description: string, icon: SymbolKind, pos: an
|
|||
return new DocumentSymbol(name, description, icon, fullrange, selrange);
|
||||
}
|
||||
|
||||
|
||||
export class Symbols implements DocumentSymbolProvider {
|
||||
provideDocumentSymbols = async (
|
||||
document: TextDocument,
|
||||
|
@ -23,34 +24,35 @@ export class Symbols implements DocumentSymbolProvider {
|
|||
channel.log("Symbols: " + document.uri);
|
||||
const symbols: DocumentSymbol[] = [];
|
||||
const text = document.getText();
|
||||
const linter = new (XQLint as any)(text, { "styleCheck": false });
|
||||
const linter = new XQLint(text, { "styleCheck": false });
|
||||
|
||||
const xqdoc = linter.getXQDoc();
|
||||
channel.log("got xqdoc");
|
||||
const prolog=new Range(0,0,0,0)
|
||||
symbols.push(makeSymbol(xqdoc.moduleNamespace || "Main", xqdoc.description, SymbolKind.Module, prolog))
|
||||
|
||||
let vars=makeSymbol("Variables", "", SymbolKind.Variable, prolog)
|
||||
vars.children=[]
|
||||
|
||||
// type: type,
|
||||
// pos: pos,
|
||||
// qname: qname,
|
||||
// annotations: {}
|
||||
xqdoc.variables.forEach(v => {
|
||||
const name = v.name;
|
||||
const info = makeSymbol(name, "", SymbolKind.Variable, v.pos)
|
||||
vars.children.push(info);
|
||||
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);
|
||||
});
|
||||
|
||||
const funs=makeSymbol("Variables", "", SymbolKind.Function, prolog)
|
||||
funs.children=[]
|
||||
xqdoc.functions.forEach(v => {
|
||||
const name = v.name +"#" + v.params.length;
|
||||
const info = makeSymbol(name, "", SymbolKind.Function, v.pos)
|
||||
funs.children.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);
|
||||
});
|
||||
symbols.push(vars)
|
||||
symbols.push(funs)
|
||||
|
||||
channel.log("Symbols done " + document.uri);
|
||||
return symbols;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue