@vue/language-service
Advanced tools
Comparing version 2.0.7 to 2.0.10
@@ -559,3 +559,3 @@ { | ||
"kind": "markdown", | ||
"value": "\nA `<style module>` tag is compiled as [CSS Modules](https://github.com/css-modules/css-modules) and exposes the resulting CSS classes to the component as an object under the key of `$style`:\n\n```vue\n<template>\n <p :class=\"$style.red\">This should be red</p>\n</template>\n\n<style module>\n.red {\n color: red;\n}\n</style>\n```\n\nThe resulting classes are hashed to avoid collision, achieving the same effect of scoping the CSS to the current component only.\n\nRefer to the [CSS Modules spec](https://github.com/css-modules/css-modules) for more details such as [global exceptions](https://github.com/css-modules/css-modules#exceptions) and [composition](https://github.com/css-modules/css-modules#composition).\n\n### Custom Inject Name \n\nYou can customize the property key of the injected classes object by giving the `module` attribute a value:\n\n```vue\n<template>\n <p :class=\"classes.red\">red</p>\n</template>\n\n<style module=\"classes\">\n.red {\n color: red;\n}\n</style>\n```\n\n### Usage with Composition API \n\nThe injected classes can be accessed in `setup()` and `<script setup>` via the `useCssModule` API. For `<style module>` blocks with custom injection names, `useCssModule` accepts the matching `module` attribute value as the first argument:\n\n```js\nimport { useCssModule } from 'vue'\n\n// inside setup() scope...\n// default, returns classes for <style module>\nuseCssModule()\n\n// named, returns classes for <style module=\"classes\">\nuseCssModule('classes')\n```\n" | ||
"value": "\nA `<style module>` tag is compiled as [CSS Modules](https://github.com/css-modules/css-modules) and exposes the resulting CSS classes to the component as an object under the key of `$style`:\n\n```vue\n<template>\n <p :class=\"$style.red\">This should be red</p>\n</template>\n\n<style module>\n.red {\n color: red;\n}\n</style>\n```\n\nThe resulting classes are hashed to avoid collision, achieving the same effect of scoping the CSS to the current component only.\n\nRefer to the [CSS Modules spec](https://github.com/css-modules/css-modules) for more details such as [global exceptions](https://github.com/css-modules/css-modules/blob/master/docs/composition.md#exceptions) and [composition](https://github.com/css-modules/css-modules/blob/master/docs/composition.md#composition).\n\n### Custom Inject Name \n\nYou can customize the property key of the injected classes object by giving the `module` attribute a value:\n\n```vue\n<template>\n <p :class=\"classes.red\">red</p>\n</template>\n\n<style module=\"classes\">\n.red {\n color: red;\n}\n</style>\n```\n\n### Usage with Composition API \n\nThe injected classes can be accessed in `setup()` and `<script setup>` via the `useCssModule` API. For `<style module>` blocks with custom injection names, `useCssModule` accepts the matching `module` attribute value as the first argument:\n\n```js\nimport { useCssModule } from 'vue'\n\n// inside setup() scope...\n// default, returns classes for <style module>\nuseCssModule()\n\n// named, returns classes for <style module=\"classes\">\nuseCssModule('classes')\n```\n" | ||
}, | ||
@@ -562,0 +562,0 @@ "references": [ |
@@ -8,3 +8,3 @@ { | ||
"kind": "markdown", | ||
"value": "\nデフォルトでは、 `v-model` は各 `input` イベントの後に、入力とデータを同期します ([上記](#vmodel-ime-tip) の IME による入力は例外とします)。 代わりに `change` イベント後に同期する `lazy` 修飾子を追加することができます。\n\n```html\n<!-- \"input\" の代わりに \"change\" イベント後に同期されます -->\n<input v-model.lazy=\"msg\" />\n```\n" | ||
"value": "\nデフォルトでは、 `v-model` は各 `input` イベントの後に、入力とデータを同期します([上記](#vmodel-ime-tip) の IME による入力は例外とします)。 代わりに `change` イベント後に同期する `lazy` 修飾子を追加することができます。\n\n```html\n<!-- \"input\" の代わりに \"change\" イベント後に同期されます -->\n<input v-model.lazy=\"msg\" />\n```\n" | ||
}, | ||
@@ -11,0 +11,0 @@ "references": [ |
@@ -5,5 +5,5 @@ export * from '@volar/language-service'; | ||
export * from './lib/types'; | ||
import type { ServiceContext, ServiceEnvironment, ServicePlugin } from '@volar/language-service'; | ||
import type { ServiceContext, ServiceEnvironment, LanguageServicePlugin } from '@volar/language-service'; | ||
import type { VueCompilerOptions } from './lib/types'; | ||
export declare function createVueServicePlugins(ts: typeof import('typescript'), getVueOptions: (env: ServiceEnvironment) => VueCompilerOptions, getTsPluginClient?: (context: ServiceContext) => typeof import("@vue/typescript-plugin/lib/client") | undefined, hybridMode?: boolean): ServicePlugin[]; | ||
export declare function createVueServicePlugins(ts: typeof import('typescript'), getVueOptions: (env: ServiceEnvironment) => VueCompilerOptions, getTsPluginClient?: (context: ServiceContext) => typeof import("@vue/typescript-plugin/lib/client") | undefined, hybridMode?: boolean): LanguageServicePlugin[]; | ||
export declare function createDefaultGetTsPluginClient(ts: typeof import('typescript'), getVueOptions: (env: ServiceEnvironment) => VueCompilerOptions): (context: ServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined; |
18
index.js
@@ -45,2 +45,3 @@ "use strict"; | ||
const componentInfos_1 = require("@vue/typescript-plugin/lib/requests/componentInfos"); | ||
const getImportPathForFile_1 = require("@vue/typescript-plugin/lib/requests/getImportPathForFile"); | ||
const getPropertiesAtLocation_1 = require("@vue/typescript-plugin/lib/requests/getPropertiesAtLocation"); | ||
@@ -64,3 +65,3 @@ const getQuickInfoAtPosition_1 = require("@vue/typescript-plugin/lib/requests/getQuickInfoAtPosition"); | ||
const vueOptions = getVueOptions(context.env); | ||
(0, common_1.decorateLanguageServiceForVue)(context.language.files, languageService, vueOptions, ts, false); | ||
(0, common_1.decorateLanguageServiceForVue)(context.language, languageService, vueOptions, ts, false); | ||
return created; | ||
@@ -76,3 +77,3 @@ }, | ||
} | ||
plugins.push((0, volar_service_typescript_twoslash_queries_1.create)(ts), (0, css_1.create)(), (0, volar_service_pug_beautify_1.create)(), (0, volar_service_json_1.create)(), (0, vue_template_1.create)('html', ts, getVueOptions, getTsPluginClient), (0, vue_template_1.create)('pug', ts, getVueOptions, getTsPluginClient), (0, vue_sfc_1.create)(), (0, vue_twoslash_queries_1.create)(ts, getTsPluginClient), (0, vue_codelens_references_1.create)(), (0, vue_document_drop_1.create)(ts), (0, vue_autoinsert_dotvalue_1.create)(ts, getTsPluginClient), (0, vue_autoinsert_parentheses_1.create)(ts), (0, vue_autoinsert_space_1.create)(), (0, vue_visualize_hidden_callback_param_1.create)(), (0, vue_directive_comments_1.create)(), (0, vue_extract_file_1.create)(ts, getTsPluginClient), (0, vue_toggle_v_bind_codeaction_1.create)(ts), (0, volar_service_emmet_1.create)()); | ||
plugins.push((0, volar_service_typescript_twoslash_queries_1.create)(ts), (0, css_1.create)(), (0, volar_service_pug_beautify_1.create)(), (0, volar_service_json_1.create)(), (0, vue_template_1.create)('html', ts, getVueOptions, getTsPluginClient), (0, vue_template_1.create)('pug', ts, getVueOptions, getTsPluginClient), (0, vue_sfc_1.create)(), (0, vue_twoslash_queries_1.create)(ts, getTsPluginClient), (0, vue_codelens_references_1.create)(), (0, vue_document_drop_1.create)(ts, getTsPluginClient), (0, vue_autoinsert_dotvalue_1.create)(ts, getTsPluginClient), (0, vue_autoinsert_parentheses_1.create)(ts), (0, vue_autoinsert_space_1.create)(), (0, vue_visualize_hidden_callback_param_1.create)(), (0, vue_directive_comments_1.create)(), (0, vue_extract_file_1.create)(ts, getTsPluginClient), (0, vue_toggle_v_bind_codeaction_1.create)(ts), (0, volar_service_emmet_1.create)()); | ||
return plugins; | ||
@@ -86,6 +87,11 @@ } | ||
} | ||
const languageService = context.inject('typescript/languageService'); | ||
if (!languageService) { | ||
return; | ||
} | ||
const requestContext = { | ||
typescript: ts, | ||
files: context.language.files, | ||
languageService: context.inject('typescript/languageService'), | ||
language: context.language, | ||
languageService, | ||
languageServiceHost: context.language.typescript.languageServiceHost, | ||
vueOptions: getVueOptions(context.env), | ||
@@ -102,2 +108,5 @@ isTsPlugin: false, | ||
}, | ||
async getImportPathForFile(...args) { | ||
return await getImportPathForFile_1.getImportPathForFile.apply(requestContext, args); | ||
}, | ||
async getComponentEvents(...args) { | ||
@@ -123,5 +132,4 @@ return await componentInfos_1.getComponentEvents.apply(requestContext, args); | ||
}; | ||
; | ||
} | ||
exports.createDefaultGetTsPluginClient = createDefaultGetTsPluginClient; | ||
//# sourceMappingURL=index.js.map |
@@ -9,7 +9,7 @@ "use strict"; | ||
async function convertTagName(context, uri, casing, tsPluginClient) { | ||
const sourceFile = context.language.files.get(uri); | ||
const sourceFile = context.language.scripts.get(uri); | ||
if (!sourceFile) { | ||
return; | ||
} | ||
const rootCode = sourceFile?.generated?.code; | ||
const rootCode = sourceFile?.generated?.root; | ||
if (!(rootCode instanceof language_core_1.VueGeneratedCode)) { | ||
@@ -47,7 +47,7 @@ return; | ||
async function convertAttrName(context, uri, casing, tsPluginClient) { | ||
const sourceFile = context.language.files.get(uri); | ||
const sourceFile = context.language.scripts.get(uri); | ||
if (!sourceFile) { | ||
return; | ||
} | ||
const rootCode = sourceFile?.generated?.code; | ||
const rootCode = sourceFile?.generated?.root; | ||
if (!(rootCode instanceof language_core_1.VueGeneratedCode)) { | ||
@@ -105,3 +105,3 @@ return; | ||
async function detect(context, uri, tsPluginClient) { | ||
const rootFile = context.language.files.get(uri)?.generated?.code; | ||
const rootFile = context.language.scripts.get(uri)?.generated?.root; | ||
if (!(rootFile instanceof language_core_1.VueGeneratedCode)) { | ||
@@ -181,3 +181,3 @@ return { | ||
if (ast) { | ||
for (const node of vue.eachElementNode(ast)) { | ||
for (const node of vue.forEachElementNode(ast)) { | ||
if (!tags.has(node.tag)) { | ||
@@ -184,0 +184,0 @@ tags.set(node.tag, { offsets: [], attrs: new Map() }); |
@@ -1,2 +0,2 @@ | ||
import type { ServicePlugin } from '@volar/language-service'; | ||
export declare function create(): ServicePlugin; | ||
import type { LanguageServicePlugin } from '@volar/language-service'; | ||
export declare function create(): LanguageServicePlugin; |
@@ -1,10 +0,10 @@ | ||
import type { ServiceContext, ServicePlugin } from '@volar/language-service'; | ||
import type { ServiceContext, LanguageServicePlugin } from '@volar/language-service'; | ||
import type * as ts from 'typescript'; | ||
import type * as vscode from 'vscode-languageserver-protocol'; | ||
import type { TextDocument } from 'vscode-languageserver-textdocument'; | ||
export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: ServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): ServicePlugin; | ||
export declare function isCharacterTyping(document: TextDocument, lastChange: { | ||
range: vscode.Range; | ||
export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: ServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): LanguageServicePlugin; | ||
export declare function isCharacterTyping(document: TextDocument, change: { | ||
text: string; | ||
rangeOffset: number; | ||
rangeLength: number; | ||
}): boolean; | ||
export declare function isBlacklistNode(ts: typeof import('typescript'), node: ts.Node, pos: number, allowAccessDotValue: boolean): boolean; |
@@ -21,7 +21,11 @@ "use strict"; | ||
return { | ||
async provideAutoInsertionEdit(document, position, lastChange) { | ||
async provideAutoInsertionEdit(document, selection, change) { | ||
// selection must at end of change | ||
if (document.offsetAt(selection) !== change.rangeOffset + change.text.length) { | ||
return; | ||
} | ||
if (!isTsDocument(document)) { | ||
return; | ||
} | ||
if (!isCharacterTyping(document, lastChange)) { | ||
if (!isCharacterTyping(document, change)) { | ||
return; | ||
@@ -39,18 +43,20 @@ } | ||
} | ||
const [code, file] = context.documents.getVirtualCodeByUri(document.uri); | ||
if (!file) { | ||
const decoded = context.decodeEmbeddedDocumentUri(document.uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); | ||
if (!sourceScript) { | ||
return; | ||
} | ||
let ast; | ||
let sourceCodeOffset = document.offsetAt(position); | ||
const fileName = context.env.typescript.uriToFileName(file.id); | ||
if (file?.generated) { | ||
const script = file.generated.languagePlugin.typescript?.getScript(file.generated.code); | ||
if (script?.code !== code) { | ||
let sourceCodeOffset = document.offsetAt(selection); | ||
const fileName = context.env.typescript.uriToFileName(sourceScript.id); | ||
if (sourceScript.generated) { | ||
const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root); | ||
if (!serviceScript || serviceScript?.code !== virtualCode) { | ||
return; | ||
} | ||
ast = getAst(ts, fileName, script.code.snapshot, script.scriptKind); | ||
ast = getAst(ts, fileName, virtualCode.snapshot, serviceScript.scriptKind); | ||
let mapped = false; | ||
for (const [_1, [_2, map]] of context.language.files.getMaps(code)) { | ||
const sourceOffset = map.getSourceOffset(document.offsetAt(position)); | ||
for (const [_1, [_2, map]] of context.language.maps.forEach(virtualCode)) { | ||
const sourceOffset = map.getSourceOffset(document.offsetAt(selection)); | ||
if (sourceOffset !== undefined) { | ||
@@ -67,5 +73,5 @@ sourceCodeOffset = sourceOffset[0]; | ||
else { | ||
ast = getAst(ts, fileName, file.snapshot); | ||
ast = getAst(ts, fileName, sourceScript.snapshot); | ||
} | ||
if (isBlacklistNode(ts, ast, document.offsetAt(position), false)) { | ||
if (isBlacklistNode(ts, ast, document.offsetAt(selection), false)) { | ||
return; | ||
@@ -93,17 +99,9 @@ } | ||
const charReg = /\w/; | ||
function isCharacterTyping(document, lastChange) { | ||
const lastCharacter = lastChange.text[lastChange.text.length - 1]; | ||
const rangeStart = lastChange.range.start; | ||
const position = { | ||
line: rangeStart.line, | ||
character: rangeStart.character + lastChange.text.length, | ||
}; | ||
const nextCharacter = document.getText({ | ||
start: position, | ||
end: { line: position.line, character: position.character + 1 }, | ||
}); | ||
function isCharacterTyping(document, change) { | ||
const lastCharacter = change.text[change.text.length - 1]; | ||
const nextCharacter = document.getText().substring(change.rangeOffset + change.text.length, change.rangeOffset + change.text.length + 1); | ||
if (lastCharacter === undefined) { // delete text | ||
return false; | ||
} | ||
if (lastChange.text.indexOf('\n') >= 0) { // multi-line change | ||
if (change.text.indexOf('\n') >= 0) { // multi-line change | ||
return false; | ||
@@ -110,0 +108,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import type { ServicePlugin } from '@volar/language-service'; | ||
export declare function create(ts: typeof import('typescript')): ServicePlugin; | ||
import type { LanguageServicePlugin } from '@volar/language-service'; | ||
export declare function create(ts: typeof import('typescript')): LanguageServicePlugin; |
@@ -10,3 +10,7 @@ "use strict"; | ||
return { | ||
async provideAutoInsertionEdit(document, position, lastChange) { | ||
async provideAutoInsertionEdit(document, selection, change) { | ||
// selection must at end of change | ||
if (document.offsetAt(selection) !== change.rangeOffset + change.text.length) { | ||
return; | ||
} | ||
const enabled = await context.env.getConfiguration?.('vue.autoInsert.parentheses') ?? false; | ||
@@ -16,10 +20,12 @@ if (!enabled) { | ||
} | ||
if (!(0, vue_autoinsert_dotvalue_1.isCharacterTyping)(document, lastChange)) { | ||
if (!(0, vue_autoinsert_dotvalue_1.isCharacterTyping)(document, change)) { | ||
return; | ||
} | ||
const [virtualCode] = context.documents.getVirtualCodeByUri(document.uri); | ||
if (virtualCode?.id !== 'template_format') { | ||
const decoded = context.decodeEmbeddedDocumentUri(document.uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); | ||
if (!virtualCode?.id.startsWith('template_inline_ts_')) { | ||
return; | ||
} | ||
const offset = document.offsetAt(position); | ||
const offset = document.offsetAt(selection); | ||
for (const mappedRange of virtualCode.mappings) { | ||
@@ -26,0 +32,0 @@ const generatedCodeEnd = mappedRange.generatedOffsets[mappedRange.generatedOffsets.length - 1] |
@@ -1,2 +0,2 @@ | ||
import type { ServicePlugin } from '@volar/language-service'; | ||
export declare function create(): ServicePlugin; | ||
import type { LanguageServicePlugin } from '@volar/language-service'; | ||
export declare function create(): LanguageServicePlugin; |
@@ -9,3 +9,3 @@ "use strict"; | ||
return { | ||
async provideAutoInsertionEdit(document, _, lastChange) { | ||
async provideAutoInsertionEdit(document, selection, change) { | ||
if (document.languageId === 'html' || document.languageId === 'jade') { | ||
@@ -16,14 +16,6 @@ const enabled = await context.env.getConfiguration?.('vue.autoInsert.bracketSpacing') ?? true; | ||
} | ||
if (lastChange.text === '{}' | ||
&& document.getText({ | ||
start: { line: lastChange.range.start.line, character: lastChange.range.start.character - 1 }, | ||
end: { line: lastChange.range.start.line, character: lastChange.range.start.character + 3 } | ||
}) === '{{}}') { | ||
return { | ||
newText: ` $0 `, | ||
range: { | ||
start: { line: lastChange.range.start.line, character: lastChange.range.start.character + 1 }, | ||
end: { line: lastChange.range.start.line, character: lastChange.range.start.character + 1 } | ||
}, | ||
}; | ||
if (change.text === '{}' | ||
&& document.getText().substring(change.rangeOffset - 1, change.rangeOffset + 3) === '{{}}' | ||
&& document.offsetAt(selection) === change.rangeOffset + 1) { | ||
return ` $0 `; | ||
} | ||
@@ -30,0 +22,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import type { ServicePlugin } from '@volar/language-service'; | ||
export declare function create(): ServicePlugin; | ||
import type { LanguageServicePlugin } from '@volar/language-service'; | ||
export declare function create(): LanguageServicePlugin; |
@@ -30,7 +30,9 @@ "use strict"; | ||
function worker(uri, callback) { | ||
const [virtualCode, sourceFile] = context.documents.getVirtualCodeByUri(uri); | ||
if (!(sourceFile?.generated?.code instanceof language_core_1.VueGeneratedCode) || !sourceFile) { | ||
const decoded = context.decodeEmbeddedDocumentUri(uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); | ||
if (!virtualCode || !(sourceScript?.generated?.root instanceof language_core_1.VueGeneratedCode) || !sourceScript) { | ||
return; | ||
} | ||
return callback(virtualCode, sourceFile); | ||
return callback(virtualCode, sourceScript); | ||
} | ||
@@ -37,0 +39,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import type { ServicePlugin } from '@volar/language-service'; | ||
export declare function create(): ServicePlugin; | ||
import type { LanguageServicePlugin } from '@volar/language-service'; | ||
export declare function create(): LanguageServicePlugin; |
@@ -1,2 +0,2 @@ | ||
import { ServicePlugin } from '../types'; | ||
export declare function create(ts: typeof import('typescript')): ServicePlugin; | ||
import { LanguageServicePlugin, ServiceContext } from '../types'; | ||
export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: ServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): LanguageServicePlugin; |
@@ -9,3 +9,4 @@ "use strict"; | ||
const types_1 = require("../types"); | ||
function create(ts) { | ||
const getUserPreferences_1 = require("volar-service-typescript/lib/configs/getUserPreferences"); | ||
function create(ts, getTsPluginClient) { | ||
return { | ||
@@ -15,2 +16,3 @@ name: 'vue-document-drop', | ||
let casing = types_1.TagNameCasing.Pascal; // TODO | ||
const tsPluginClient = getTsPluginClient?.(context); | ||
return { | ||
@@ -21,5 +23,7 @@ async provideDocumentDropEdits(document, _position, dataTransfer) { | ||
} | ||
const [virtualCode, sourceFile] = context.documents.getVirtualCodeByUri(document.uri); | ||
const vueVirtualCode = sourceFile?.generated?.code; | ||
if (!virtualCode || !(vueVirtualCode instanceof language_core_1.VueGeneratedCode)) { | ||
const decoded = context.decodeEmbeddedDocumentUri(document.uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); | ||
const vueVirtualCode = sourceScript?.generated?.root; | ||
if (!sourceScript || !virtualCode || !(vueVirtualCode instanceof language_core_1.VueGeneratedCode)) { | ||
return; | ||
@@ -47,10 +51,24 @@ } | ||
const lastImportNode = (0, vue_extract_file_1.getLastImportNode)(ts, script.ast); | ||
let importPath = path.relative(path.dirname(document.uri), importUri) | ||
|| importUri.substring(importUri.lastIndexOf('/') + 1); | ||
if (!importPath.startsWith('./') && !importPath.startsWith('../')) { | ||
importPath = './' + importPath; | ||
const incomingFileName = context.env.typescript.uriToFileName(importUri); | ||
let importPath; | ||
const serviceScript = sourceScript.generated?.languagePlugin.typescript?.getServiceScript(vueVirtualCode); | ||
if (tsPluginClient && serviceScript) { | ||
const tsDocumentUri = context.encodeEmbeddedDocumentUri(sourceScript.id, serviceScript.code.id); | ||
const tsDocument = context.documents.get(tsDocumentUri, serviceScript.code.languageId, serviceScript.code.snapshot); | ||
const preferences = await (0, getUserPreferences_1.getUserPreferences)(context, tsDocument); | ||
const importPathRequest = await tsPluginClient.getImportPathForFile(vueVirtualCode.fileName, incomingFileName, preferences); | ||
if (importPathRequest) { | ||
importPath = importPathRequest; | ||
} | ||
} | ||
if (!importPath) { | ||
importPath = path.relative(path.dirname(vueVirtualCode.fileName), incomingFileName) | ||
|| importUri.substring(importUri.lastIndexOf('/') + 1); | ||
if (!importPath.startsWith('./') && !importPath.startsWith('../')) { | ||
importPath = './' + importPath; | ||
} | ||
} | ||
additionalEdit.changes ??= {}; | ||
additionalEdit.changes[context.documents.getVirtualCodeUri(sourceFile.id, code.id)] = []; | ||
additionalEdit.changes[context.documents.getVirtualCodeUri(sourceFile.id, code.id)].push({ | ||
additionalEdit.changes[context.encodeEmbeddedDocumentUri(sourceScript.id, code.id)] = []; | ||
additionalEdit.changes[context.encodeEmbeddedDocumentUri(sourceScript.id, code.id)].push({ | ||
range: lastImportNode ? { | ||
@@ -69,3 +87,3 @@ start: script.ast.getLineAndCharacterOfPosition(lastImportNode.end), | ||
if (edit) { | ||
additionalEdit.changes[context.documents.getVirtualCodeUri(sourceFile.id, code.id)].push({ | ||
additionalEdit.changes[context.encodeEmbeddedDocumentUri(sourceScript.id, code.id)].push({ | ||
range: { | ||
@@ -72,0 +90,0 @@ start: document.positionAt(edit.range.start), |
@@ -1,4 +0,4 @@ | ||
import type { ServiceContext, ServicePlugin } from '@volar/language-service'; | ||
import type { ServiceContext, LanguageServicePlugin } from '@volar/language-service'; | ||
import type * as ts from 'typescript'; | ||
export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: ServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): ServicePlugin; | ||
export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: ServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): LanguageServicePlugin; | ||
export declare function getLastImportNode(ts: typeof import('typescript'), sourceFile: ts.SourceFile): ts.Node | undefined; | ||
@@ -5,0 +5,0 @@ export declare function createAddComponentToOptionEdit(ts: typeof import('typescript'), ast: ts.SourceFile, componentName: string): { |
@@ -18,7 +18,9 @@ "use strict"; | ||
} | ||
const [code, vueCode] = context.documents.getVirtualCodeByUri(document.uri); | ||
if (!(vueCode?.generated?.code instanceof language_core_1.VueGeneratedCode) || code?.id !== 'template') { | ||
const decoded = context.decodeEmbeddedDocumentUri(document.uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); | ||
if (!(sourceScript?.generated?.root instanceof language_core_1.VueGeneratedCode) || virtualCode?.id !== 'template') { | ||
return; | ||
} | ||
const { sfc } = vueCode.generated.code; | ||
const { sfc } = sourceScript.generated.root; | ||
const script = sfc.scriptSetup ?? sfc.script; | ||
@@ -47,9 +49,11 @@ if (!sfc.template || !script) { | ||
const [startOffset, endOffset] = range; | ||
const [code, sourceFile] = context.documents.getVirtualCodeByUri(uri); | ||
if (!(sourceFile?.generated?.code instanceof language_core_1.VueGeneratedCode) || code?.id !== 'template') { | ||
const decoded = context.decodeEmbeddedDocumentUri(uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); | ||
if (!(sourceScript?.generated?.root instanceof language_core_1.VueGeneratedCode) || virtualCode?.id !== 'template') { | ||
return codeAction; | ||
} | ||
const document = context.documents.get(uri, code.languageId, code.snapshot); | ||
const sfcDocument = context.documents.get(sourceFile.id, sourceFile.languageId, sourceFile.snapshot); | ||
const { sfc } = sourceFile.generated.code; | ||
const document = context.documents.get(uri, virtualCode.languageId, virtualCode.snapshot); | ||
const sfcDocument = context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot); | ||
const { sfc } = sourceScript.generated.root; | ||
const script = sfc.scriptSetup ?? sfc.script; | ||
@@ -63,3 +67,3 @@ if (!sfc.template || !script) { | ||
} | ||
const toExtract = await tsPluginClient?.collectExtractProps(sourceFile.generated.code.fileName, templateCodeRange) ?? []; | ||
const toExtract = await tsPluginClient?.collectExtractProps(sourceScript.generated.root.fileName, templateCodeRange) ?? []; | ||
if (!toExtract) { | ||
@@ -128,3 +132,3 @@ return codeAction; | ||
textDocument: { | ||
uri: sourceFile.id, | ||
uri: sourceScript.id, | ||
version: null, | ||
@@ -131,0 +135,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import type { ServicePlugin } from '@volar/language-service'; | ||
import type { LanguageServicePlugin } from '@volar/language-service'; | ||
import * as vue from '@vue/language-core'; | ||
@@ -7,2 +7,2 @@ import type { TextDocument } from 'vscode-languageserver-textdocument'; | ||
} | ||
export declare function create(): ServicePlugin; | ||
export declare function create(): LanguageServicePlugin; |
@@ -20,4 +20,22 @@ "use strict"; | ||
}, | ||
async getFormattingOptions(document, options, context) { | ||
return await worker(document, async (vueCode) => { | ||
const formatSettings = await context.env.getConfiguration?.('html.format') ?? {}; | ||
const blockTypes = ['template', 'script', 'style']; | ||
for (const customBlock of vueCode.sfc.customBlocks) { | ||
blockTypes.push(customBlock.type); | ||
} | ||
return { | ||
...options, | ||
...formatSettings, | ||
wrapAttributes: 'auto', | ||
unformatted: '', | ||
contentUnformatted: blockTypes.join(','), | ||
endWithNewline: options.insertFinalNewline ? true | ||
: options.trimFinalNewlines ? false | ||
: document.getText().endsWith('\n'), | ||
}; | ||
}) ?? {}; | ||
}, | ||
}).create(context); | ||
const htmlLanguageService = htmlPlugin.provide['html/languageService'](); | ||
return { | ||
@@ -32,6 +50,5 @@ ...htmlPlugin, | ||
}, | ||
async resolveEmbeddedCodeFormattingOptions(code, options) { | ||
const sourceFile = context.language.files.getByVirtualCode(code); | ||
if (sourceFile.generated?.code instanceof vue.VueGeneratedCode) { | ||
if (code.id === 'scriptFormat' || code.id === 'scriptSetupFormat') { | ||
async resolveEmbeddedCodeFormattingOptions(sourceScript, virtualCode, options) { | ||
if (sourceScript.generated?.root instanceof vue.VueGeneratedCode) { | ||
if (virtualCode.id === 'scriptFormat' || virtualCode.id === 'scriptSetupFormat') { | ||
if (await context.env.getConfiguration?.('vue.format.script.initialIndent') ?? false) { | ||
@@ -41,3 +58,3 @@ options.initialIndentLevel++; | ||
} | ||
else if (code.id.startsWith('style_')) { | ||
else if (virtualCode.id.startsWith('style_')) { | ||
if (await context.env.getConfiguration?.('vue.format.style.initialIndent') ?? false) { | ||
@@ -47,3 +64,3 @@ options.initialIndentLevel++; | ||
} | ||
else if (code.id === 'template') { | ||
else if (virtualCode.id === 'template') { | ||
if (await context.env.getConfiguration?.('vue.format.template.initialIndent') ?? true) { | ||
@@ -141,25 +158,9 @@ options.initialIndentLevel++; | ||
}, | ||
provideDocumentFormattingEdits(document, range, options) { | ||
return worker(document, async (vueCode) => { | ||
const formatSettings = await context.env.getConfiguration?.('html.format') ?? {}; | ||
const blockTypes = ['template', 'script', 'style']; | ||
for (const customBlock of vueCode.sfc.customBlocks) { | ||
blockTypes.push(customBlock.type); | ||
} | ||
return htmlLanguageService.format(document, range, { | ||
...options, | ||
...formatSettings, | ||
unformatted: '', | ||
contentUnformatted: blockTypes.join(','), | ||
endWithNewline: options.insertFinalNewline ? true | ||
: options.trimFinalNewlines ? false | ||
: document.getText().endsWith('\n'), | ||
}); | ||
}); | ||
}, | ||
}; | ||
function worker(document, callback) { | ||
const [vueFile] = context.documents.getVirtualCodeByUri(document.uri); | ||
if (vueFile instanceof vue.VueGeneratedCode) { | ||
return callback(vueFile); | ||
const decoded = context.decodeEmbeddedDocumentUri(document.uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); | ||
if (virtualCode instanceof vue.VueGeneratedCode) { | ||
return callback(virtualCode); | ||
} | ||
@@ -166,0 +167,0 @@ } |
import type { ServiceContext, ServiceEnvironment } from '@volar/language-service'; | ||
import { ServicePlugin, VueCompilerOptions } from '../types'; | ||
export declare function create(mode: 'html' | 'pug', ts: typeof import('typescript'), getVueOptions: (env: ServiceEnvironment) => VueCompilerOptions, getTsPluginClient?: (context: ServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): ServicePlugin; | ||
import { LanguageServicePlugin, VueCompilerOptions } from '../types'; | ||
export declare function create(mode: 'html' | 'pug', ts: typeof import('typescript'), getVueOptions: (env: ServiceEnvironment) => VueCompilerOptions, getTsPluginClient?: (context: ServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): LanguageServicePlugin; |
@@ -92,5 +92,6 @@ "use strict"; | ||
let currentVersion; | ||
const [_, sourceFile] = context.documents.getVirtualCodeByUri(document.uri); | ||
if (sourceFile?.generated?.code instanceof language_core_1.VueGeneratedCode) { | ||
sync = (await provideHtmlData(sourceFile.id, sourceFile.generated.code)).sync; | ||
const decoded = context.decodeEmbeddedDocumentUri(document.uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
if (sourceScript?.generated?.root instanceof language_core_1.VueGeneratedCode) { | ||
sync = (await provideHtmlData(sourceScript.id, sourceScript.generated.root)).sync; | ||
currentVersion = await sync(); | ||
@@ -105,4 +106,4 @@ } | ||
} | ||
if (sourceFile?.generated?.code instanceof language_core_1.VueGeneratedCode) { | ||
await afterHtmlCompletion(htmlComplete, context.documents.get(sourceFile.id, sourceFile.languageId, sourceFile.snapshot), sourceFile.generated.code); | ||
if (sourceScript?.generated?.root instanceof language_core_1.VueGeneratedCode) { | ||
await afterHtmlCompletion(htmlComplete, context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot), sourceScript.generated.root); | ||
} | ||
@@ -120,3 +121,5 @@ return htmlComplete; | ||
const result = []; | ||
const [virtualCode] = context.documents.getVirtualCodeByUri(document.uri); | ||
const decoded = context.decodeEmbeddedDocumentUri(document.uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); | ||
if (!virtualCode) { | ||
@@ -126,3 +129,3 @@ return; | ||
for (const map of context.documents.getMaps(virtualCode)) { | ||
const code = context.language.files.get(map.sourceDocument.uri)?.generated?.code; | ||
const code = context.language.scripts.get(map.sourceDocument.uri)?.generated?.root; | ||
const scanner = getScanner(baseServiceInstance, document); | ||
@@ -220,3 +223,3 @@ if (code instanceof language_core_1.VueGeneratedCode && scanner) { | ||
} | ||
if (context.documents.getVirtualCodeByUri(document.uri)[0]) { | ||
if (context.decodeEmbeddedDocumentUri(document.uri)) { | ||
updateExtraCustomData([]); | ||
@@ -231,3 +234,5 @@ } | ||
const originalResult = await baseServiceInstance.provideDiagnostics?.(document, token); | ||
const [virtualCode] = context.documents.getVirtualCodeByUri(document.uri); | ||
const decoded = context.decodeEmbeddedDocumentUri(document.uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); | ||
if (!virtualCode) { | ||
@@ -237,3 +242,3 @@ return; | ||
for (const map of context.documents.getMaps(virtualCode)) { | ||
const code = context.language.files.get(map.sourceDocument.uri)?.generated?.code; | ||
const code = context.language.scripts.get(map.sourceDocument.uri)?.generated?.root; | ||
if (!(code instanceof language_core_1.VueGeneratedCode)) { | ||
@@ -279,15 +284,20 @@ continue; | ||
} | ||
const [_virtualCode, sourceFile] = context.documents.getVirtualCodeByUri(document.uri); | ||
if (!sourceFile | ||
|| !(sourceFile.generated?.code instanceof language_core_1.VueGeneratedCode) | ||
|| !sourceFile.generated.code.sfc.template) { | ||
const languageService = context.inject('typescript/languageService'); | ||
if (!languageService) { | ||
return; | ||
} | ||
const decoded = context.decodeEmbeddedDocumentUri(document.uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
if (!sourceScript | ||
|| !(sourceScript.generated?.root instanceof language_core_1.VueGeneratedCode) | ||
|| !sourceScript.generated.root.sfc.template) { | ||
return []; | ||
} | ||
const { template } = sourceFile.generated.code.sfc; | ||
const { template } = sourceScript.generated.root.sfc; | ||
const spans = common_1.getComponentSpans.call({ | ||
files: context.language.files, | ||
languageService: context.inject('typescript/languageService'), | ||
files: context.language.scripts, | ||
languageService, | ||
typescript: ts, | ||
vueOptions: getVueOptions(context.env), | ||
}, sourceFile.generated.code, template, { | ||
}, sourceScript.generated.root, template, { | ||
start: document.offsetAt(range.start), | ||
@@ -294,0 +304,0 @@ length: document.offsetAt(range.end) - document.offsetAt(range.start), |
@@ -1,2 +0,2 @@ | ||
import type { ServicePlugin } from '@volar/language-service'; | ||
export declare function create(ts: typeof import('typescript')): ServicePlugin; | ||
import type { LanguageServicePlugin } from '@volar/language-service'; | ||
export declare function create(ts: typeof import('typescript')): LanguageServicePlugin; |
@@ -13,3 +13,5 @@ "use strict"; | ||
const endOffset = document.offsetAt(range.end); | ||
const [virtualCode] = context.documents.getVirtualCodeByUri(document.uri); | ||
const decoded = context.decodeEmbeddedDocumentUri(document.uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); | ||
if (!(virtualCode instanceof language_core_1.VueGeneratedCode)) { | ||
@@ -24,3 +26,3 @@ return; | ||
const result = []; | ||
for (const node of (0, language_core_1.eachElementNode)(template.ast)) { | ||
for (const node of (0, language_core_1.forEachElementNode)(template.ast)) { | ||
if (startOffset > templateStartOffset + node.loc.end.offset || endOffset < templateStartOffset + node.loc.start.offset) { | ||
@@ -27,0 +29,0 @@ return; |
@@ -1,2 +0,2 @@ | ||
import type { ServiceContext, ServicePlugin } from '@volar/language-service'; | ||
export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: ServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): ServicePlugin; | ||
import type { ServiceContext, LanguageServicePlugin } from '@volar/language-service'; | ||
export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: ServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): LanguageServicePlugin; |
@@ -13,4 +13,6 @@ "use strict"; | ||
async provideInlayHints(document, range) { | ||
const [virtualCode, sourceFile] = context.documents.getVirtualCodeByUri(document.uri); | ||
if (!(sourceFile?.generated?.code instanceof vue.VueGeneratedCode) || virtualCode?.id !== 'template') { | ||
const decoded = context.decodeEmbeddedDocumentUri(document.uri); | ||
const sourceScript = decoded && context.language.scripts.get(decoded[0]); | ||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); | ||
if (!(sourceScript?.generated?.root instanceof vue.VueGeneratedCode) || virtualCode?.id !== 'template') { | ||
return; | ||
@@ -29,5 +31,5 @@ } | ||
for (const [pointerPosition, hoverOffset] of hoverOffsets) { | ||
for (const [_1, [_2, map]] of context.language.files.getMaps(virtualCode)) { | ||
for (const [_1, [_2, map]] of context.language.maps.forEach(virtualCode)) { | ||
for (const [sourceOffset] of map.getSourceOffsets(hoverOffset)) { | ||
const quickInfo = await tsPluginClient?.getQuickInfoAtPosition(sourceFile.generated.code.fileName, sourceOffset); | ||
const quickInfo = await tsPluginClient?.getQuickInfoAtPosition(sourceScript.generated.root.fileName, sourceOffset); | ||
if (quickInfo) { | ||
@@ -34,0 +36,0 @@ inlayHints.push({ |
@@ -1,2 +0,2 @@ |
import type { ServicePlugin } from '../types'; |
export declare function create(): ServicePlugin; |
import type { LanguageServicePlugin } from '../types'; |
export declare function create(): LanguageServicePlugin; |
@@ -12,7 +12,9 @@ "use strict"; |
const result = []; |
const [vitualFile] = context.documents.getVirtualCodeByUri(document.uri); |
if (vitualFile) { |
const decoded = context.decodeEmbeddedDocumentUri(document.uri); |
const sourceScript = decoded && context.language.scripts.get(decoded[0]); |
const vitualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); |
if (vitualCode) { |
const start = document.offsetAt(range.start); |
const end = document.offsetAt(range.end); |
for (const mapping of vitualFile.mappings) { |
for (const mapping of vitualCode.mappings) { |
const hint = mapping.data.__hint; |
@@ -19,0 +21,0 @@ if (mapping.generatedOffsets[0] >= start |
{ | ||
"name": "@vue/language-service", | ||
"version": "2.0.7", | ||
"version": "2.0.10", | ||
"license": "MIT", | ||
@@ -19,19 +19,19 @@ "files": [ | ||
"dependencies": { | ||
"@volar/language-core": "~2.1.3", | ||
"@volar/language-service": "~2.1.3", | ||
"@volar/typescript": "~2.1.3", | ||
"@volar/language-core": "~2.2.0-alpha.5", | ||
"@volar/language-service": "~2.2.0-alpha.5", | ||
"@volar/typescript": "~2.2.0-alpha.5", | ||
"@vue/compiler-dom": "^3.4.0", | ||
"@vue/language-core": "2.0.7", | ||
"@vue/language-core": "2.0.10", | ||
"@vue/shared": "^3.4.0", | ||
"@vue/typescript-plugin": "2.0.7", | ||
"@vue/typescript-plugin": "2.0.10", | ||
"computeds": "^0.0.1", | ||
"path-browserify": "^1.0.1", | ||
"volar-service-css": "0.0.34", | ||
"volar-service-emmet": "0.0.34", | ||
"volar-service-html": "0.0.34", | ||
"volar-service-json": "0.0.34", | ||
"volar-service-pug": "0.0.34", | ||
"volar-service-pug-beautify": "0.0.34", | ||
"volar-service-typescript": "0.0.34", | ||
"volar-service-typescript-twoslash-queries": "0.0.34", | ||
"volar-service-css": "0.0.38", | ||
"volar-service-emmet": "0.0.38", | ||
"volar-service-html": "0.0.38", | ||
"volar-service-json": "0.0.38", | ||
"volar-service-pug": "0.0.38", | ||
"volar-service-pug-beautify": "0.0.38", | ||
"volar-service-typescript": "0.0.38", | ||
"volar-service-typescript-twoslash-queries": "0.0.38", | ||
"vscode-html-languageservice": "^5.1.0", | ||
@@ -44,6 +44,6 @@ "vscode-languageserver-textdocument": "^1.0.11", | ||
"@types/path-browserify": "latest", | ||
"@volar/kit": "~2.1.3", | ||
"@volar/kit": "~2.2.0-alpha.5", | ||
"vscode-languageserver-protocol": "^3.17.5" | ||
}, | ||
"gitHead": "4a37e8f3ebcf31ecfd2ea627f7611d5990ec5df6" | ||
"gitHead": "a20a2ee950b63a949660b7e8faf0faed0e5bad33" | ||
} |
Sorry, the diff of this file is too big to display
955318
19108
+ Added@volar/language-core@2.2.5(transitive)
+ Added@volar/language-service@2.2.5(transitive)
+ Added@volar/source-map@2.2.5(transitive)
+ Added@volar/typescript@2.2.5(transitive)
+ Added@vue/language-core@2.0.10(transitive)
+ Added@vue/typescript-plugin@2.0.10(transitive)
+ Addedvolar-service-css@0.0.38(transitive)
+ Addedvolar-service-emmet@0.0.38(transitive)
+ Addedvolar-service-html@0.0.38(transitive)
+ Addedvolar-service-json@0.0.38(transitive)
+ Addedvolar-service-pug@0.0.38(transitive)
+ Addedvolar-service-pug-beautify@0.0.38(transitive)
+ Addedvolar-service-typescript@0.0.38(transitive)
+ Addedvolar-service-typescript-twoslash-queries@0.0.38(transitive)
- Removed@volar/language-core@2.1.6(transitive)
- Removed@volar/language-service@2.1.6(transitive)
- Removed@volar/source-map@2.1.6(transitive)
- Removed@volar/typescript@2.1.6(transitive)
- Removed@vue/language-core@2.0.7(transitive)
- Removed@vue/typescript-plugin@2.0.7(transitive)
- Removedvolar-service-css@0.0.34(transitive)
- Removedvolar-service-emmet@0.0.34(transitive)
- Removedvolar-service-html@0.0.34(transitive)
- Removedvolar-service-json@0.0.34(transitive)
- Removedvolar-service-pug@0.0.34(transitive)
- Removedvolar-service-pug-beautify@0.0.34(transitive)
- Removedvolar-service-typescript@0.0.34(transitive)
- Removedvolar-service-typescript-twoslash-queries@0.0.34(transitive)
Updated@vue/language-core@2.0.10
Updatedvolar-service-css@0.0.38
Updatedvolar-service-emmet@0.0.38
Updatedvolar-service-html@0.0.38
Updatedvolar-service-json@0.0.38
Updatedvolar-service-pug@0.0.38