From a5a8134ea750b1cbd3e79cff16985dec55bd00be Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sat, 2 Nov 2024 21:24:03 +0100 Subject: [PATCH] refactor(vetur): remove vetur package --- packages/vetur/LICENSE | 21 -- packages/vetur/README.md | 30 --- packages/vetur/index.ts | 299 --------------------------- packages/vetur/lib/userSnippetDir.ts | 15 -- packages/vetur/package.json | 42 ---- packages/vetur/tsconfig.json | 4 - tsconfig.base.json | 2 - tsconfig.json | 1 - 8 files changed, 414 deletions(-) delete mode 100644 packages/vetur/LICENSE delete mode 100644 packages/vetur/README.md delete mode 100644 packages/vetur/index.ts delete mode 100644 packages/vetur/lib/userSnippetDir.ts delete mode 100644 packages/vetur/package.json delete mode 100644 packages/vetur/tsconfig.json diff --git a/packages/vetur/LICENSE b/packages/vetur/LICENSE deleted file mode 100644 index e2ac49ce..00000000 --- a/packages/vetur/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022-present Johnson Chu - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/vetur/README.md b/packages/vetur/README.md deleted file mode 100644 index 14fb7776..00000000 --- a/packages/vetur/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# volar-service-vetur - -Volar plugin for [VLS](https://www.npmjs.com/package/vls). - -With this plugin you can use this Vetur base features in Volar: - -- [Customizable Scaffold Snippets](https://vuejs.github.io/vetur/guide/snippet.html#customizable-scaffold-snippets) -- [Component Data](https://vuejs.github.io/vetur/guide/component-data.html#supported-frameworks) - -## Installation - -```sh -npm install volar-service-vetur -``` - -## Usage - -`volar.config.js` - -```js -module.exports = { - services: [ - require('volar-service-vetur').create(), - ], -}; -``` - -## License - -[MIT](LICENSE) © [Johnson Chu](https://github.com/johnsoncodehk) diff --git a/packages/vetur/index.ts b/packages/vetur/index.ts deleted file mode 100644 index 00c68748..00000000 --- a/packages/vetur/index.ts +++ /dev/null @@ -1,299 +0,0 @@ -import type { LanguageServicePlugin, LanguageServicePluginInstance, SemanticToken } from '@volar/language-service'; -import * as fs from 'fs'; -import * as path from 'path'; -import * as vls from 'vls'; -import type { TextDocument } from 'vscode-html-languageservice'; -import * as html from 'vscode-html-languageservice'; -import { URI } from 'vscode-uri'; -import { getGlobalSnippetDir } from './lib/userSnippetDir'; - -export function create(): LanguageServicePlugin { - return { - name: 'vetur', - capabilities: { - completionProvider: { - // https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/html-language-features/server/src/htmlServer.ts#L183 - triggerCharacters: ['.', ':', '<', '"', '=', '/', /* vue event shorthand */'@'], - }, - hoverProvider: true, - semanticTokensProvider: { - legend: { - tokenTypes: ['function'], - tokenModifiers: [], - }, - }, - }, - create(): LanguageServicePluginInstance { - - const htmlDocuments = new WeakMap(); - const uriToPackageJsonPath = new Map(); - const htmlDataProviders = new Map(); - const htmlLs = html.getLanguageService(); - const snippetManager = new vls.SnippetManager(getSnippetsPath() ?? ''/* TODO: find snippets folder from document path */, getGlobalSnippetDir(false)); - const scaffoldSnippetSources: vls.ScaffoldSnippetSources = { - workspace: '💼', - user: '🗒️', - vetur: '✌' - }; - - return { - - isAdditionalCompletion: true, - - provideCompletionItems(document, position, context) { - - let result: html.CompletionList | undefined; - - htmlWorker(document, htmlDocument => { - result = htmlLs.doComplete(document, position, htmlDocument); - }); - - if (!context.triggerCharacter) { - vueWorker(document, () => { - const items = snippetManager.completeSnippets(scaffoldSnippetSources); - if (items.length) { - result = { - isIncomplete: false, - items: items, - }; - } - }); - } - - return result; - }, - - provideHover(document, position) { - return htmlWorker(document, htmlDocument => { - return htmlLs.doHover(document, position, htmlDocument); - }); - }, - - provideDocumentSemanticTokens(document, range, legend) { - return htmlWorker(document, () => { - - const packageJsonPath = getPackageJsonPath(document); - if (!packageJsonPath) { - return; - } - - const dtmlDataProviders = getHtmlDataProviders(packageJsonPath); - const components = new Set(dtmlDataProviders.map(provider => provider.getId() === 'html5' ? [] : provider.provideTags().map(tag => tag.name)).flat()); - const offsetRange = { - start: document.offsetAt(range.start), - end: document.offsetAt(range.end), - }; - const scanner = htmlLs.createScanner(document.getText()); - const result: SemanticToken[] = []; - - let token = scanner.scan(); - - while (token !== html.TokenType.EOS) { - - const tokenOffset = scanner.getTokenOffset(); - - // TODO: fix source map perf and break in while condition - if (tokenOffset > offsetRange.end) { - break; - } - - if (tokenOffset >= offsetRange.start && (token === html.TokenType.StartTag || token === html.TokenType.EndTag)) { - - const tokenText = scanner.getTokenText(); - - if (components.has(tokenText) || tokenText.indexOf('.') >= 0) { - - const tokenLength = scanner.getTokenLength(); - const tokenPosition = document.positionAt(tokenOffset); - - if (components.has(tokenText)) { - result.push([tokenPosition.line, tokenPosition.character, tokenLength, legend.tokenTypes.indexOf('function'), 0]); - } - } - } - token = scanner.scan(); - } - - return result; - }); - }, - }; - - function htmlWorker(document: TextDocument, callback: (htmlDocument: html.HTMLDocument) => T) { - - const htmlDocument = getHtmlDocument(document); - if (!htmlDocument) { - return; - } - - const packageJsonPath = getPackageJsonPath(document); - if (!packageJsonPath) { - return; - } - - htmlLs.setDataProviders( - false, - getHtmlDataProviders(packageJsonPath) - ); - - return callback(htmlDocument); - } - - function vueWorker(document: TextDocument, callback: () => T) { - if (document.languageId === 'vue') { - return callback(); - } - } - - function getPackageJsonPath(document: TextDocument) { - - let packageJsonPath = uriToPackageJsonPath.get(document.uri); - - if (!packageJsonPath) { - - const uri = URI.parse(document.uri); - - if (uri.scheme === 'file') { - - let lastDirname = uri.fsPath.replace(/\\/g, '/'); - - while (true) { - - const dirname = path.dirname(lastDirname); - if (dirname === lastDirname) { - break; - } - - if (fs.existsSync(dirname + '/package.json')) { - packageJsonPath = dirname + '/package.json'; - break; - } - - lastDirname = dirname; - } - } - - uriToPackageJsonPath.set(document.uri, packageJsonPath); - } - - return packageJsonPath; - } - - function getSnippetsPath() { - - const fsPath = __filename; - - let lastDirname = fsPath; - let snippetsPath: string | undefined; - - while (true) { - - const dirname = path.dirname(lastDirname); - if (dirname === lastDirname) { - break; - } - - if (fs.existsSync(dirname + '/.vscode/vetur/snippets')) { - snippetsPath = dirname + '/.vscode/vetur/snippets'; - break; - } - - lastDirname = dirname; - } - - return snippetsPath; - } - - function getHtmlDataProviders(packageJsonPath: string) { - - let dataProviders = htmlDataProviders.get(packageJsonPath); - - if (!dataProviders) { - - const tagProviderSettings = vls.getTagProviderSettings(packageJsonPath); - const enabledTagProviders = vls.getEnabledTagProviders(tagProviderSettings); - - dataProviders = enabledTagProviders.map(provider => { - const htmlProvider: html.IHTMLDataProvider = { - getId: provider.getId, - isApplicable() { - return true; - }, - provideTags() { - const tags: html.ITagData[] = []; - provider.collectTags((tag, documentation) => { - tags.push({ - name: tag, - description: documentation, - attributes: [], - }); - }); - return tags; - }, - provideAttributes(tag) { - const attributes: html.IAttributeData[] = []; - provider.collectAttributes(tag, (attribute, type, documentation) => { - if (attribute.startsWith('v-') || attribute.startsWith('@')) { - attributes.push({ - name: attribute, - valueSet: type, - description: documentation, - }); - } - else { - attributes.push({ - name: 'v-bind:' + attribute, - valueSet: type, - description: documentation, - }); - attributes.push({ - name: ':' + attribute, - valueSet: type, - description: documentation, - }); - attributes.push({ - name: attribute, - valueSet: type, - description: documentation, - }); - } - }); - return attributes; - }, - provideValues(tag, attribute) { - const values: html.IValueData[] = []; - provider.collectValues(tag, attribute, value => { - values.push({ - name: value, - }); - }); - return values; - }, - }; - return htmlProvider; - }); - - htmlDataProviders.set(packageJsonPath, dataProviders); - } - - return dataProviders; - } - - function getHtmlDocument(document: TextDocument) { - - if (document.languageId !== 'html') { - return; - } - - let htmlDocument = htmlDocuments.get(document); - - if (!htmlDocument) { - htmlDocument = htmlLs.parseHTMLDocument(document); - htmlDocuments.set(document, htmlDocument); - } - - return htmlDocument; - } - }, - }; -} diff --git a/packages/vetur/lib/userSnippetDir.ts b/packages/vetur/lib/userSnippetDir.ts deleted file mode 100644 index cad92aa6..00000000 --- a/packages/vetur/lib/userSnippetDir.ts +++ /dev/null @@ -1,15 +0,0 @@ -// https://github.com/vuejs/vetur/blob/master/client/userSnippetDir.ts -import { homedir } from 'os'; -import { resolve } from 'path'; - -export function getGlobalSnippetDir(isInsiders: boolean) { - const appName = isInsiders ? 'Code - Insiders' : 'Code'; - - if (process.platform === 'win32') { - return resolve(process.env['APPDATA'] || '', appName, 'User/snippets/vetur'); - } else if (process.platform === 'darwin') { - return resolve(homedir(), 'Library/Application Support', appName, 'User/snippets/vetur'); - } else { - return resolve(homedir(), '.config', appName, 'User/snippets/vetur'); - } -} diff --git a/packages/vetur/package.json b/packages/vetur/package.json deleted file mode 100644 index 8e84badd..00000000 --- a/packages/vetur/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "volar-service-vetur", - "version": "0.0.62", - "description": "Integrate Vetur into Volar", - "homepage": "https://github.com/volarjs/services/tree/master/packages/vetur", - "bugs": "https://github.com/volarjs/services/issues", - "sideEffects": false, - "keywords": [ - "volar-service" - ], - "license": "MIT", - "files": [ - "**/*.js", - "**/*.d.ts" - ], - "repository": { - "type": "git", - "url": "https://github.com/volarjs/services.git", - "directory": "packages/vetur" - }, - "author": { - "name": "Johnson Chu", - "email": "johnsoncodehk@gmail.com", - "url": "https://github.com/johnsoncodehk" - }, - "dependencies": { - "vls": "^0.8.5", - "vscode-html-languageservice": "^5.3.0", - "vscode-uri": "^3.0.8" - }, - "peerDependencies": { - "@volar/language-service": "~2.4.0" - }, - "peerDependenciesMeta": { - "@volar/language-service": { - "optional": true - } - }, - "devDependencies": { - "@types/node": "latest" - } -} diff --git a/packages/vetur/tsconfig.json b/packages/vetur/tsconfig.json deleted file mode 100644 index 45b22f96..00000000 --- a/packages/vetur/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": [ "*", "lib/**/*" ], -} diff --git a/tsconfig.base.json b/tsconfig.base.json index 42501040..d74f6436 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -15,8 +15,6 @@ "noUnusedParameters": true, "esModuleInterop": false, "forceConsistentCasingInFileNames": true, - "ignoreDeprecations": "5.0", - "importsNotUsedAsValues": "error", }, "include": [ ], } diff --git a/tsconfig.json b/tsconfig.json index 0bf25f19..9d4cd6e2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,6 @@ { "path": "./packages/sass-formatter/tsconfig.json" }, { "path": "./packages/typescript/tsconfig.json" }, { "path": "./packages/typescript-twoslash-queries/tsconfig.json" }, - { "path": "./packages/vetur/tsconfig.json" }, { "path": "./packages/yaml/tsconfig.json" }, ], }