Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: document features stop working for script block
close #1813
- Loading branch information
1 parent
1116427
commit 28b56e0
Showing
4 changed files
with
56 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
packages/vue-language-service/src/utils/singleFileTypeScriptService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { TextDocument } from 'vscode-languageserver-textdocument'; | ||
import type * as ts2 from '@volar/typescript-language-service'; | ||
import { URI } from 'vscode-uri'; | ||
import * as shared from '@volar/shared'; | ||
|
||
let projectVersion = 0; | ||
let doc: TextDocument; | ||
let fileName: string; | ||
let scriptSnapshot: ts.IScriptSnapshot; | ||
let service: ts2.LanguageService | undefined; | ||
|
||
const host: ts.LanguageServiceHost = { | ||
readFile: () => undefined, | ||
fileExists: fileName => fileName === fileName, | ||
getProjectVersion: () => projectVersion.toString(), | ||
getScriptVersion: () => projectVersion.toString(), | ||
getCompilationSettings: () => ({ allowJs: true, jsx: 1 }), | ||
getScriptFileNames: () => [fileName], | ||
getScriptSnapshot: fileName => { | ||
if (fileName === fileName) { | ||
return scriptSnapshot; | ||
} | ||
}, | ||
getCurrentDirectory: () => '', | ||
getDefaultLibFileName: () => '', | ||
}; | ||
|
||
export function getSingleFileTypeScriptService( | ||
ts: typeof import('typescript/lib/tsserverlibrary'), | ||
ts2: typeof import('@volar/typescript-language-service'), | ||
_doc: TextDocument, | ||
settings: ts2.Settings, | ||
): ts2.LanguageService { | ||
if (!service) { | ||
service = ts2.createLanguageService( | ||
ts, | ||
host, | ||
ts.createLanguageService(host), | ||
settings, | ||
URI.file('/'), | ||
); | ||
} | ||
projectVersion++; | ||
doc = _doc; | ||
fileName = shared.getPathOfUri(_doc.uri); | ||
scriptSnapshot = ts.ScriptSnapshot.fromString(doc.getText()); | ||
return service; | ||
} |