Skip to content

Commit

Permalink
fix(typescript): cannot convert extra file name to embedded uri
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 30, 2024
1 parent 5e38dfc commit f3b454b
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions packages/typescript/lib/plugins/semantic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export function create(
if (!context.language.typescript) {
return {};
}
const { sys, languageServiceHost, asFileName, asScriptId } = context.language.typescript;
const { sys, languageServiceHost, asFileName, asScriptId, getExtraServiceScript } = context.language.typescript;
const created = tsWithImportCache.createLanguageService(
ts,
sys,
Expand Down Expand Up @@ -231,7 +231,7 @@ export function create(
function updateSourceScriptFileNames() {
sourceScriptNames.clear();
for (const fileName of languageServiceHost.getScriptFileNames()) {
const uri = asScriptId(fileName);
const uri = ctx.fileNameToUri(fileName);
const sourceScript = context.language.scripts.get(uri);
if (sourceScript?.generated) {
const tsCode = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
Expand All @@ -258,20 +258,16 @@ export function create(
return asFileName(uri);
},
fileNameToUri(fileName) {
const extraServiceScript = getExtraServiceScript(fileName);
if (extraServiceScript) {
return context.encodeEmbeddedDocumentUri(extraServiceScript[0].id, extraServiceScript[1].code.id);
}

const uri = asScriptId(fileName);
const sourceScript = context.language.scripts.get(uri);
const extraServiceScript = context.language.typescript!.getExtraServiceScript(fileName);

let virtualCode = extraServiceScript?.code;

if (!virtualCode && sourceScript?.generated?.languagePlugin.typescript) {
const serviceScript = sourceScript.generated.languagePlugin.typescript.getServiceScript(sourceScript.generated.root);
if (serviceScript) {
virtualCode = serviceScript.code;
}
}
if (sourceScript && virtualCode) {
return context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id);
const serviceScript = sourceScript?.generated?.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
if (sourceScript && serviceScript) {
return context.encodeEmbeddedDocumentUri(sourceScript.id, serviceScript.code.id);
}

return uri;
Expand Down

0 comments on commit f3b454b

Please sign in to comment.