[add] setting to control hover display
This commit is contained in:
		
							parent
							
								
									73925db367
								
							
						
					
					
						commit
						93e6b0a1d6
					
				
					 7 changed files with 52 additions and 43 deletions
				
			
		
							
								
								
									
										6
									
								
								.github/workflows/release.yml
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.github/workflows/release.yml
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -10,10 +10,12 @@ jobs:
 | 
			
		|||
    runs-on: "ubuntu-latest"
 | 
			
		||||
    steps:
 | 
			
		||||
    - name: "Checkout"
 | 
			
		||||
      uses: "actions/checkout@v2"
 | 
			
		||||
      uses: "actions/checkout@v3"
 | 
			
		||||
    
 | 
			
		||||
    - name: "Setup NodeJS"
 | 
			
		||||
      uses: "actions/setup-node@v2.1.0"
 | 
			
		||||
      uses: "actions/setup-node@v3"
 | 
			
		||||
      with:
 | 
			
		||||
        node-version: 16
 | 
			
		||||
        
 | 
			
		||||
    - name: "Install Dependencies"
 | 
			
		||||
      run: "npm install"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3
									
								
								.vscode/settings.json
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.vscode/settings.json
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -5,5 +5,6 @@
 | 
			
		|||
    },
 | 
			
		||||
    "search.exclude": {
 | 
			
		||||
        "out": true // set this to false to include "out" folder in search results
 | 
			
		||||
    }
 | 
			
		||||
    },
 | 
			
		||||
    "basexTools.xquery.showHovers": false
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,12 +1,14 @@
 | 
			
		|||
# 0.1.1 (2023-02-21)
 | 
			
		||||
* Add Hover show option
 | 
			
		||||
# 0.1.0 (2023-02-19)
 | 
			
		||||
Update xqlint to 0.2.0
 | 
			
		||||
* Update xqlint to 0.2.0
 | 
			
		||||
 | 
			
		||||
# 0.0.64 (2023-01-26)
 | 
			
		||||
* add simple hover display
 | 
			
		||||
* 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
 | 
			
		||||
* Use xqlint 0.0.14
 | 
			
		||||
 | 
			
		||||
# 0.0.48
 | 
			
		||||
* Fix xmlToText #6
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										30
									
								
								package.json
									
										
									
									
									
								
							
							
						
						
									
										30
									
								
								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.1.1",
 | 
			
		||||
  "preview": true,
 | 
			
		||||
  "publisher": "quodatum",
 | 
			
		||||
  "author": "Andy Bunce (https://github.com/Quodatum)",
 | 
			
		||||
| 
						 | 
				
			
			@ -15,7 +15,7 @@
 | 
			
		|||
  "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"
 | 
			
		||||
| 
						 | 
				
			
			@ -31,15 +31,6 @@
 | 
			
		|||
    "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",
 | 
			
		||||
| 
						 | 
				
			
			@ -125,6 +116,11 @@
 | 
			
		|||
        "id": "xquery",
 | 
			
		||||
        "title": "XQuery ",
 | 
			
		||||
        "properties": {
 | 
			
		||||
          "basexTools.xquery.showHovers": {
 | 
			
		||||
              "type": "boolean",
 | 
			
		||||
              "default": false,
 | 
			
		||||
              "description": "Show hovers in xquery."
 | 
			
		||||
          },
 | 
			
		||||
          "basexTools.xquery.executionArguments": {
 | 
			
		||||
            "type": "array",
 | 
			
		||||
            "default": [
 | 
			
		||||
| 
						 | 
				
			
			@ -159,34 +155,34 @@
 | 
			
		|||
        }
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        "title": "BaseX Tools ",
 | 
			
		||||
        "title": "XML edit ",
 | 
			
		||||
        "type": "object",
 | 
			
		||||
        "properties": {
 | 
			
		||||
          "basexTools.enforcePrettySelfClosingTagOnFormat": {
 | 
			
		||||
          "basexTools.xml.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": {
 | 
			
		||||
          "basexTools.xml.removeCommentsOnMinify": {
 | 
			
		||||
            "type": "boolean",
 | 
			
		||||
            "default": false,
 | 
			
		||||
            "description": "Remove XML comments during minification.",
 | 
			
		||||
            "scope": "resource"
 | 
			
		||||
          },
 | 
			
		||||
          "basexTools.splitAttributesOnFormat": {
 | 
			
		||||
          "basexTools.xml.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": {
 | 
			
		||||
          "basexTools.xml.splitXmlnsOnFormat": {
 | 
			
		||||
            "type": "boolean",
 | 
			
		||||
            "default": true,
 | 
			
		||||
            "description": "Put each xmlns attribute on a new line when formatting XML.",
 | 
			
		||||
            "scope": "resource"
 | 
			
		||||
          },
 | 
			
		||||
          "basexTools.xmlFormatterImplementation": {
 | 
			
		||||
          "basexTools.xml.FormatterImplementation": {
 | 
			
		||||
            "type": "string",
 | 
			
		||||
            "enum": [
 | 
			
		||||
              "classic",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,7 +24,7 @@ export class Configuration {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    static get xmlFormatterImplementation(): string {
 | 
			
		||||
        return this._getForWindow<string>("xmlFormatterImplementation");
 | 
			
		||||
        return this._getForWindow<string>("xml.FormatterImplementation");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static get xqueryExecutionArguments(): string[] {
 | 
			
		||||
| 
						 | 
				
			
			@ -43,20 +43,24 @@ export class Configuration {
 | 
			
		|||
        return this._getForWindow<string>("xquery.executionInputSearchPattern");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static xqueryShowHovers(resource: Uri): boolean {
 | 
			
		||||
        return this._getForResource<boolean>("xquery.showHovers", resource);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static enforcePrettySelfClosingTagOnFormat(resource: Uri): boolean {
 | 
			
		||||
        return this._getForResource<boolean>("enforcePrettySelfClosingTagOnFormat", resource);
 | 
			
		||||
        return this._getForResource<boolean>("xml.enforcePrettySelfClosingTagOnFormat", resource);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static removeCommentsOnMinify(resource: Uri): boolean {
 | 
			
		||||
        return this._getForResource<boolean>("removeCommentsOnMinify", resource);
 | 
			
		||||
        return this._getForResource<boolean>("xml.removeCommentsOnMinify", resource);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static splitAttributesOnFormat(resource: Uri): boolean {
 | 
			
		||||
        return this._getForResource<boolean>("splitAttributesOnFormat", resource);
 | 
			
		||||
        return this._getForResource<boolean>("xml.splitAttributesOnFormat", resource);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static splitXmlnsOnFormat(resource: Uri): boolean {
 | 
			
		||||
        return this._getForResource<boolean>("splitXmlnsOnFormat", resource);
 | 
			
		||||
        return this._getForResource<boolean>("xml.splitXmlnsOnFormat", resource);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static _getForResource<T>(section: string, resource: Uri): T {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,7 +32,7 @@ export class ClassicXmlFormatter implements XmlFormatter {
 | 
			
		|||
                output += parts[i];
 | 
			
		||||
                inComment = false;
 | 
			
		||||
            } else if (/^<(\w|:)/.test(parts[i - 1]) && /^<\/(\w|:)/.test(parts[i])
 | 
			
		||||
                && /^<[\w:\-\.\,\/]+/.exec(parts[i - 1])[0] === /^<\/[\w:\-\.\,]+/.exec(parts[i])[0].replace("/", "")) {
 | 
			
		||||
                && /^<[\w:\-.,/]+/.exec(parts[i - 1])[0] === /^<\/[\w:\-.,]+/.exec(parts[i])[0].replace("/", "")) {
 | 
			
		||||
 | 
			
		||||
                output += parts[i];
 | 
			
		||||
                if (!inComment) { level--; }
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +48,7 @@ export class ClassicXmlFormatter implements XmlFormatter {
 | 
			
		|||
                output = (!inComment) ? output += this._getIndent(options, level--, parts[i]) : output += parts[i];
 | 
			
		||||
            } else if (parts[i].search(/<\?/) > -1) {
 | 
			
		||||
                output += this._getIndent(options, level, parts[i]);
 | 
			
		||||
            } else if (options.splitXmlnsOnFormat && (parts[i].search(/xmlns\:/) > -1 || parts[i].search(/xmlns\=/) > -1)) {
 | 
			
		||||
            } else if (options.splitXmlnsOnFormat && (parts[i].search(/xmlns:/) > -1 || parts[i].search(/xmlns=/) > -1)) {
 | 
			
		||||
                output += this._getIndent(options, level, parts[i]);
 | 
			
		||||
            } else {
 | 
			
		||||
                output += parts[i];
 | 
			
		||||
| 
						 | 
				
			
			@ -67,7 +67,7 @@ export class ClassicXmlFormatter implements XmlFormatter {
 | 
			
		|||
 | 
			
		||||
    minifyXml(xml: string, options: XmlFormattingOptions): string {
 | 
			
		||||
        xml = this._stripLineBreaks(options, xml); // all line breaks outside of CDATA elements and comments
 | 
			
		||||
        xml = (options.removeCommentsOnMinify) ? xml.replace(/\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>/g, "") : xml;
 | 
			
		||||
        xml = (options.removeCommentsOnMinify) ? xml.replace(/<![ \r\n\t]*(--([^-]|[\r\n]|-[^-])*--[ \r\n\t]*)>/g, "") : xml;
 | 
			
		||||
        xml = xml.replace(/>\s{0,}</g, "><"); // insignificant whitespace between tags
 | 
			
		||||
        xml = xml.replace(/"\s+(?=[^\s]+=)/g, "\" "); // spaces between attributes
 | 
			
		||||
        xml = xml.replace(/"\s+(?=>)/g, "\""); // spaces between the last attribute and tag close (>)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,8 @@
 | 
			
		|||
// xquery hover
 | 
			
		||||
 | 
			
		||||
import { CancellationToken, Hover, HoverProvider, Position, TextDocument } from "vscode";
 | 
			
		||||
import { XQLint} from "@quodatum/xqlint";
 | 
			
		||||
import { XQLint } from "@quodatum/xqlint";
 | 
			
		||||
import { Configuration } from "../common";
 | 
			
		||||
 | 
			
		||||
export class XQueryHoverProvider implements HoverProvider {
 | 
			
		||||
    public provideHover(
 | 
			
		||||
| 
						 | 
				
			
			@ -11,7 +12,7 @@ export class XQueryHoverProvider implements HoverProvider {
 | 
			
		|||
    ): Hover | null {
 | 
			
		||||
        const linter = new XQLint(document.getText());
 | 
			
		||||
 | 
			
		||||
        const node=linter.getAST(position);
 | 
			
		||||
        const node = linter.getAST(position);
 | 
			
		||||
        //const sctx=linter.getCompletions(position);
 | 
			
		||||
        //channel.log("Hover: " + node.name);
 | 
			
		||||
        //const dx=dump(node);
 | 
			
		||||
| 
						 | 
				
			
			@ -19,10 +20,13 @@ export class XQueryHoverProvider implements HoverProvider {
 | 
			
		|||
        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 }
 | 
			
		||||
           `);
 | 
			
		||||
 
 | 
			
		||||
        if (Configuration.xqueryShowHovers(document.uri)) {
 | 
			
		||||
            return new Hover(`XQuery Hover info: ${word} at ${position.line}: ${position.character}
 | 
			
		||||
          value: ${node.value}, name: ${node.name}
 | 
			
		||||
           `);
 | 
			
		||||
        } else {
 | 
			
		||||
            return null; //if there is no information to show
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue