@vue/language-service
Advanced tools
Comparing version 2.0.26-alpha.1 to 2.0.26-alpha.2
37
index.js
@@ -49,3 +49,2 @@ "use strict"; | ||
const getPropertiesAtLocation_1 = require("@vue/typescript-plugin/lib/requests/getPropertiesAtLocation"); | ||
const getQuickInfoAtPosition_1 = require("@vue/typescript-plugin/lib/requests/getQuickInfoAtPosition"); | ||
const vscode_uri_1 = require("vscode-uri"); | ||
@@ -124,4 +123,34 @@ const nameCasing_1 = require("./lib/ideFeatures/nameCasing"); | ||
}, | ||
async getQuickInfoAtPosition(...args) { | ||
return await getQuickInfoAtPosition_1.getQuickInfoAtPosition.apply(requestContext, args); | ||
async getQuickInfoAtPosition(fileName, position) { | ||
const languageService = context.getLanguageService(); | ||
const uri = context.project.typescript.uriConverter.asUri(fileName); | ||
const sourceScript = context.language.scripts.get(uri); | ||
if (!sourceScript) { | ||
return; | ||
} | ||
const document = context.documents.get(uri, sourceScript.languageId, sourceScript.snapshot); | ||
const hover = await languageService.getHover(uri, document.positionAt(position)); | ||
let text = ''; | ||
if (typeof hover?.contents === 'string') { | ||
text = hover.contents; | ||
} | ||
else if (Array.isArray(hover?.contents)) { | ||
text = hover.contents.map(c => typeof c === 'string' ? c : c.value).join('\n'); | ||
} | ||
else if (hover) { | ||
text = hover.contents.value; | ||
} | ||
text = text.replace(/```typescript/g, ''); | ||
text = text.replace(/```/g, ''); | ||
text = text.replace(/---/g, ''); | ||
text = text.trim(); | ||
while (true) { | ||
const newText = text.replace(/\n\n/g, '\n'); | ||
if (newText === text) { | ||
break; | ||
} | ||
text = newText; | ||
} | ||
text = text.replace(/\n/g, ' | '); | ||
return text; | ||
}, | ||
@@ -152,3 +181,3 @@ }; | ||
(0, vue_sfc_1.create)(), | ||
(0, vue_twoslash_queries_1.create)(ts, getTsPluginClient), | ||
(0, vue_twoslash_queries_1.create)(getTsPluginClient), | ||
(0, vue_document_links_1.create)(), | ||
@@ -155,0 +184,0 @@ (0, vue_document_drop_1.create)(ts, getTsPluginClient), |
import type { LanguageServiceContext, LanguageServicePlugin } from '@volar/language-service'; | ||
export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: LanguageServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): LanguageServicePlugin; | ||
export declare function create(getTsPluginClient?: (context: LanguageServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): LanguageServicePlugin; |
@@ -7,3 +7,3 @@ "use strict"; | ||
const twoslashReg = /<!--\s*\^\?\s*-->/g; | ||
function create(ts, getTsPluginClient) { | ||
function create(getTsPluginClient) { | ||
return { | ||
@@ -35,16 +35,14 @@ name: 'vue-twoslash-queries', | ||
for (const [pointerPosition, hoverOffset] of hoverOffsets) { | ||
for (const [_sourceScript, map] of context.language.maps.forEach(virtualCode)) { | ||
for (const [sourceOffset] of map.toSourceLocation(hoverOffset)) { | ||
const quickInfo = await tsPluginClient?.getQuickInfoAtPosition(sourceScript.generated.root.fileName, sourceOffset); | ||
if (quickInfo) { | ||
inlayHints.push({ | ||
position: { line: pointerPosition.line, character: pointerPosition.character + 2 }, | ||
label: ts.displayPartsToString(quickInfo.displayParts), | ||
paddingLeft: true, | ||
paddingRight: false, | ||
}); | ||
break; | ||
} | ||
const map = context.language.maps.get(virtualCode, sourceScript); | ||
for (const [sourceOffset] of map.toSourceLocation(hoverOffset)) { | ||
const quickInfo = await tsPluginClient?.getQuickInfoAtPosition(sourceScript.generated.root.fileName, sourceOffset); | ||
if (quickInfo) { | ||
inlayHints.push({ | ||
position: { line: pointerPosition.line, character: pointerPosition.character + 2 }, | ||
label: quickInfo, | ||
paddingLeft: true, | ||
paddingRight: false, | ||
}); | ||
break; | ||
} | ||
break; | ||
} | ||
@@ -51,0 +49,0 @@ } |
{ | ||
"name": "@vue/language-service", | ||
"version": "2.0.26-alpha.1", | ||
"version": "2.0.26-alpha.2", | ||
"license": "MIT", | ||
@@ -19,9 +19,9 @@ "files": [ | ||
"dependencies": { | ||
"@volar/language-core": "~2.4.0-alpha.11", | ||
"@volar/language-service": "~2.4.0-alpha.11", | ||
"@volar/typescript": "~2.4.0-alpha.11", | ||
"@volar/language-core": "~2.4.0-alpha.12", | ||
"@volar/language-service": "~2.4.0-alpha.12", | ||
"@volar/typescript": "~2.4.0-alpha.12", | ||
"@vue/compiler-dom": "^3.4.0", | ||
"@vue/language-core": "2.0.26-alpha.1", | ||
"@vue/language-core": "2.0.26-alpha.2", | ||
"@vue/shared": "^3.4.0", | ||
"@vue/typescript-plugin": "2.0.26-alpha.1", | ||
"@vue/typescript-plugin": "2.0.26-alpha.2", | ||
"computeds": "^0.0.1", | ||
@@ -44,6 +44,6 @@ "path-browserify": "^1.0.1", | ||
"@types/path-browserify": "latest", | ||
"@volar/kit": "~2.4.0-alpha.11", | ||
"@volar/kit": "~2.4.0-alpha.12", | ||
"vscode-languageserver-protocol": "^3.17.5" | ||
}, | ||
"gitHead": "38830a5e043a97158c7123995914bce6a875125a" | ||
"gitHead": "e4e8c8ca14dc564bf9043a625dd704b32bdc69d0" | ||
} |
1564769
33779
+ Added@vue/language-core@2.0.26-alpha.2(transitive)
+ Added@vue/typescript-plugin@2.0.26-alpha.2(transitive)
- Removed@vue/language-core@2.0.26-alpha.1(transitive)
- Removed@vue/typescript-plugin@2.0.26-alpha.1(transitive)