Skip to content

Commit

Permalink
fix(typescript-twoslash-queries): fix invalid fileName
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 14, 2024
1 parent c4fa09f commit b4877d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/typescript-twoslash-queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export function create(ts: typeof import('typescript')): LanguageServicePlugin {
if (isTsDocument(document.languageId)) {

const languageService = context.inject<Provide, 'typescript/languageService'>('typescript/languageService');
if (!languageService) {
const fileName = context.inject<Provide, 'typescript/documentFileName'>('typescript/documentFileName', document.uri);
if (!languageService || !fileName) {
return;
}

Expand All @@ -24,7 +25,6 @@ export function create(ts: typeof import('typescript')): LanguageServicePlugin {
character: pointerPosition.character,
});

const fileName = context.env.typescript!.uriToFileName(document.uri);
const quickInfo = languageService.getQuickInfoAtPosition(fileName, hoverOffset);
if (quickInfo) {
inlayHints.push({
Expand Down
4 changes: 4 additions & 0 deletions packages/typescript/lib/plugins/semantic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import type { SharedContext } from '../semanticFeatures/types';
export interface Provide {
'typescript/languageService': () => ts.LanguageService;
'typescript/languageServiceHost': () => ts.LanguageServiceHost;
'typescript/documentFileName': (uri: string) => string;
'typescript/documentUri': (fileName: string) => string;
}

export interface CompletionItemData {
Expand Down Expand Up @@ -225,6 +227,8 @@ export function create(
provide: {
'typescript/languageService': () => languageService,
'typescript/languageServiceHost': () => languageServiceHost,
'typescript/documentFileName': uri => ctx.uriToFileName(uri),
'typescript/documentUri': fileName => ctx.fileNameToUri(fileName),
},

dispose() {
Expand Down

0 comments on commit b4877d2

Please sign in to comment.