Compare commits
1 commit
master
...
vscode-bas
Author | SHA1 | Date | |
---|---|---|---|
d7238f5d69 |
23 changed files with 2587 additions and 5183 deletions
.vscodeignoreCHANGELOG.mdCONTRIBUTING.mdREADME.mdazure-pipelines.yml
languages/xquery
package-lock.jsonpackage.jsonsrc
|
@ -1,7 +1,6 @@
|
|||
node_modules
|
||||
#out/
|
||||
src/
|
||||
tsconfig.json
|
||||
vsc-extension-quickstart.md
|
||||
.github
|
||||
.gitignore
|
||||
.vscode
|
||||
|
|
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -1,14 +1,4 @@
|
|||
# 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
|
||||
Detailed release notes are available [here](https://github.com/DotJoshJohnson/vscode-xml/releases).
|
||||
|
||||
0.0.27 doc format
|
||||
0.0.4 [add] treat schematron (.sch) as XML
|
30
CONTRIBUTING.md
Normal file
30
CONTRIBUTING.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Contributing to XML Tools
|
||||
Welcome and thank you for contributing to **XML Tools for Visual Studio Code**! This document aims to provide an overview of standards and expectations for those interested in contributing to the project.
|
||||
|
||||
## Asking Questions
|
||||
If you have any questions, please ask on Gitter or Twitter instead of submitting an issue.
|
||||
|
||||
## Reporting Issues
|
||||
Before submitting a new issue, please be sure to check for an existing issue that matches yours first. Issues that are waiting for information for more than 30 days will be closed, so please be sure to follow your issues!
|
||||
|
||||
## Writing Code
|
||||
If you would like to contribute code to the project, please follow these conventions:
|
||||
|
||||
* Use spaces over tabs (4 spaces per tab is preferred).
|
||||
* Use double quotes whenever possible instead of single quotes.
|
||||
* Use **snake-case** for file names.
|
||||
* Use **PascalCase** for class and interface names.
|
||||
* Use **camelCase** for all other identifiers unless otherwise specified.
|
||||
* Prefix private members with an underscore.
|
||||
* Implement and maintain barrels (`index.ts` files) when creating new folders or files.
|
||||
* Use constants when referencing a static value more than once in your code.
|
||||
* Place `else` and `else if` on their own lines.
|
||||
* Never put opening braces (`{`) on their own line.
|
||||
* Always use semicolons.
|
||||
* Always prefer `const` whenever possible and fall back to `let` only if absolutely necessary.
|
||||
|
||||
### Branches and Pull Requests
|
||||
Always develop on a new feature branch in your fork and submit pull requests from that branch to our master branch. Don't worry about changing any version numbers - that happens in its own PR before a release.
|
||||
|
||||
### Formatter Changes
|
||||
For small bug fixes or feature additions, always add a new test case to accompany your change. If you are making large sweeping changes to how the formatter works or leveraging an external dependency for formatting XML, please create a new XmlFormatter implementation.
|
52
README.md
52
README.md
|
@ -1,55 +1,33 @@
|
|||
# BaseX Tools for Visual Studio Code
|
||||
This project provides tools to support use of XQuery in BaseX
|
||||
This project was originally a fork of https://github.com/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
|
||||
This extension adds features to support BaseX development on VSCode.
|
||||
* XQuery 3.1, XQuery update, Full text syntax support
|
||||
* XQuery code format
|
||||
|
||||
## Features
|
||||
* [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)
|
||||
|
||||
* [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)
|
||||
|
||||
## Requirements
|
||||
* VS Code `1.63.0` or higher
|
||||
|
||||
## Release Notes
|
||||
Detailed release notes are available [here](https://git.quodatum.duckdns.org/apb/vscode-basex/releases).
|
||||
Detailed release notes are available [here](https://github.com/DotJoshJohnson/vscode-xml/releases).
|
||||
|
||||
## Issues
|
||||
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]
|
||||
Run into a bug? Report it [here](https://github.com/DotJoshJohnson/vscode-xml/issues).
|
||||
|
||||
## 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.
|
32
azure-pipelines.yml
Normal file
32
azure-pipelines.yml
Normal file
|
@ -0,0 +1,32 @@
|
|||
name: "$(Build.SourceBranchName)-$(Build.SourceVersion)$(Rev:.r)"
|
||||
pr:
|
||||
- master
|
||||
|
||||
trigger:
|
||||
- "refs/tags/*"
|
||||
|
||||
pool:
|
||||
vmImage: "windows-2019"
|
||||
|
||||
steps:
|
||||
- task: NodeTool@0
|
||||
inputs:
|
||||
versionSpec: "10.x"
|
||||
displayName: "Install NodeJS"
|
||||
|
||||
- script: |
|
||||
npm install -g vsce
|
||||
displayName: "Install VSCE"
|
||||
|
||||
- script: |
|
||||
npm install
|
||||
displayName: "NPM Install"
|
||||
|
||||
- script: |
|
||||
vsce package --out "$(Build.ArtifactStagingDirectory)/xml-$(Build.SourceBranchName)-$(Build.SourceVersion).vsix"
|
||||
displayName: "VSCE Package"
|
||||
|
||||
- task: PublishBuildArtifacts@1
|
||||
inputs:
|
||||
pathtoPublish: $(Build.ArtifactStagingDirectory)
|
||||
artifactName: drop
|
|
@ -1,19 +1,20 @@
|
|||
{
|
||||
"comments": {
|
||||
"lineComment": ["(:", ":)"],
|
||||
"blockComment": [ "(:", ":)"]
|
||||
"blockComment": [ "(:~", "~:)"]
|
||||
},
|
||||
"brackets": [
|
||||
[ "{", "}" ],
|
||||
[ "[", "]" ],
|
||||
[ "(", ")" ]
|
||||
],
|
||||
"surroundingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["'", "'"],
|
||||
["\"", "\""],
|
||||
["`", "`"]
|
||||
]
|
||||
[
|
||||
"{",
|
||||
"}"
|
||||
],
|
||||
[
|
||||
"[",
|
||||
"]"
|
||||
],
|
||||
[
|
||||
"(",
|
||||
")"
|
||||
]
|
||||
]
|
||||
}
|
||||
|
|
7367
package-lock.json
generated
7367
package-lock.json
generated
File diff suppressed because it is too large
Load diff
38
package.json
38
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.1.0",
|
||||
"version": "0.0.53",
|
||||
"preview": true,
|
||||
"publisher": "quodatum",
|
||||
"author": "Andy Bunce (https://github.com/Quodatum)",
|
||||
|
@ -15,13 +15,13 @@
|
|||
"homepage": "https://github.com/Quodatum/vscode-basex",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Quodatum/vscode-basex.git"
|
||||
"url": "https://github.com/Quodatum/vscode-basex.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Quodatum/vscode-basex/issues"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.73.0"
|
||||
"vscode": "^1.63.0"
|
||||
},
|
||||
"categories": [
|
||||
"Formatters",
|
||||
|
@ -37,12 +37,11 @@
|
|||
"onCommand:basexTools.textToXml",
|
||||
"onCommand:basexTools.xmlToText",
|
||||
"onCommand:basexTools.minifyXml",
|
||||
"onCommand:basexTools.xqLintReport",
|
||||
"onLanguage:xml",
|
||||
"onLanguage:xquery",
|
||||
"onLanguage:xsl"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"main": "./out/extension",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
|
@ -74,14 +73,15 @@
|
|||
"title": "BaseX Tools: Minify XML"
|
||||
},
|
||||
{
|
||||
"command": "basexTools.xqLintReport",
|
||||
"title": "BaseX Tools: Analysis of current location in Xquery source"
|
||||
"command": "basexTools.getAST",
|
||||
"title": "BaseX Tools: AST"
|
||||
}
|
||||
],
|
||||
"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,12 +119,11 @@
|
|||
"description": "Remember the last XPath query used.",
|
||||
"scope": "window"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
}
|
||||
},{
|
||||
"id": "xquery",
|
||||
"title": "XQuery ",
|
||||
"properties": {
|
||||
"properties":{
|
||||
"basexTools.xquery.executionArguments": {
|
||||
"type": "array",
|
||||
"default": [
|
||||
|
@ -157,8 +156,8 @@
|
|||
"scope": "window"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
},{
|
||||
"title": "BaseX Tools ",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -168,6 +167,7 @@
|
|||
"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.73.0",
|
||||
"@types/vscode": "^1.63.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.7.3"
|
||||
"typescript": "^4.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@quodatum/xqlint": "^0.2.0",
|
||||
"@quodatum/xqlint": "^0.0.11",
|
||||
"@xmldom/xmldom": "^0.8.1",
|
||||
"xpath": "0.0.32"
|
||||
}
|
||||
}
|
||||
}
|
42
src/@quodatum/xqlint.d.ts
vendored
42
src/@quodatum/xqlint.d.ts
vendored
|
@ -1,44 +1,6 @@
|
|||
|
||||
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 XQLint(source :string, opts :object) :any;
|
||||
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;
|
||||
|
|
5
src/CHANGELOG.md
Normal file
5
src/CHANGELOG.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# 0.0.48
|
||||
* Fix xmlToText #6
|
||||
* FIX outline all vars
|
||||
|
||||
# 0.0.47
|
|
@ -8,23 +8,6 @@ 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{
|
||||
|
@ -33,9 +16,6 @@ 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 xqLintReport = "basexTools.xqLintReport";
|
||||
export const getAST = "basexTools.getAST";
|
||||
}
|
||||
|
||||
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,xqLintReport } from "./linting";
|
||||
import { XQueryLinter,getAst } from "./linting";
|
||||
import { XmlTreeDataProvider } from "./tree-view";
|
||||
import { evaluateXPath, getCurrentXPath } from "./xpath/commands";
|
||||
import { executeXQuery } from "./xquery-execution/commands";
|
||||
|
@ -16,7 +16,6 @@ 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;
|
||||
|
||||
|
@ -40,7 +39,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.xqLintReport, xqLintReport),
|
||||
commands.registerTextEditorCommand(constants.commands.getAST, getAst),
|
||||
|
||||
languages.registerDocumentFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider),
|
||||
languages.registerDocumentRangeFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider),
|
||||
|
@ -54,9 +53,6 @@ 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,7 +1,10 @@
|
|||
import { Range, TextEditor, TextEditorEdit } from "vscode";
|
||||
import { workspace } from "vscode";
|
||||
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
|
||||
|
||||
import * as constants from "../../constants";
|
||||
|
||||
import { XmlFormatterFactory } from "../xml-formatter";
|
||||
import { 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,6 +1,7 @@
|
|||
import { EndOfLine, FormattingOptions, TextDocument } from "vscode";
|
||||
|
||||
import { Configuration } from "../common";
|
||||
import * as constants from "../constants";
|
||||
|
||||
export interface XmlFormattingOptions {
|
||||
editorOptions: FormattingOptions;
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
// xquery hover
|
||||
|
||||
import { CancellationToken, Hover, HoverProvider, Position, TextDocument } from "vscode";
|
||||
import { XQLint} from "@quodatum/xqlint";
|
||||
|
||||
export class XQueryHoverProvider implements HoverProvider {
|
||||
public provideHover(
|
||||
document: TextDocument,
|
||||
position: Position,
|
||||
token: CancellationToken
|
||||
): Hover | null {
|
||||
const linter = new XQLint(document.getText());
|
||||
|
||||
const node=linter.getAST(position);
|
||||
//const sctx=linter.getCompletions(position);
|
||||
//channel.log("Hover: " + node.name);
|
||||
//const dx=dump(node);
|
||||
//channel.appendLine(dx);
|
||||
const range = document.getWordRangeAtPosition(position);
|
||||
|
||||
const word = document.getText(range);
|
||||
return new Hover(`XQuery Hover info: ${word} at ${position.line}: ${position.character}
|
||||
value: ${ node.value }, name: ${ node.name }
|
||||
`);
|
||||
|
||||
return null; //if there is no information to show
|
||||
}
|
||||
}
|
23
src/linting/getAST.ts
Normal file
23
src/linting/getAST.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
|
||||
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 "./report";
|
||||
export * from "./getAST";
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
|
||||
import { TextEditor } from "vscode";
|
||||
import { XQLint} from "@quodatum/xqlint";
|
||||
import { channel,dump } from "../common/logger";
|
||||
|
||||
|
||||
export function xqLintReport(textEditor: TextEditor): void {
|
||||
const linter = new XQLint(textEditor.document.getText());
|
||||
textEditor.edit(textEdit => {
|
||||
const selections = textEditor.selections;
|
||||
selections.forEach(selection => {
|
||||
const pos=selection.start.translate(1,1); //@TODO
|
||||
const node=linter.getAST(pos);
|
||||
const sctx=linter.getCompletions(pos);
|
||||
const dx=dump(node);
|
||||
channel.appendLine(dx);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -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 { VarDecl, FunDecl, XQLint } from '@quodatum/xqlint';
|
||||
import { XQLint } from '@quodatum/xqlint';
|
||||
import {SymbolKind, DocumentSymbol, DocumentSymbolProvider,
|
||||
Range, Position, TextDocument,CancellationToken} from 'vscode';
|
||||
import { channel } from "../common/logger";
|
||||
//
|
||||
// This class handles XQuery Symbols
|
||||
// This class handles Symbols
|
||||
//
|
||||
function makeSymbol(name: string, description: string, icon: SymbolKind, pos: any) {
|
||||
const spos = new Position(pos.sl, pos.sc);
|
||||
|
@ -14,7 +14,6 @@ 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,
|
||||
|
@ -24,35 +23,34 @@ export class Symbols implements DocumentSymbolProvider {
|
|||
channel.log("Symbols: " + document.uri);
|
||||
const symbols: DocumentSymbol[] = [];
|
||||
const text = document.getText();
|
||||
const linter = new XQLint(text, { "styleCheck": false });
|
||||
const linter = new (XQLint as any)(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(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.variables.forEach(v => {
|
||||
const name = v.name;
|
||||
const info = makeSymbol(name, "", SymbolKind.Variable, v.pos)
|
||||
vars.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);
|
||||
const funs=makeSymbol("Functions", "", 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);
|
||||
});
|
||||
|
||||
symbols.push(vars)
|
||||
symbols.push(funs)
|
||||
channel.log("Symbols done " + document.uri);
|
||||
return symbols;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue