diff --git a/packages/language-server/src/plugins/typescript/DocumentSnapshot.ts b/packages/language-server/src/plugins/typescript/DocumentSnapshot.ts index aaf2a11e6..360506824 100644 --- a/packages/language-server/src/plugins/typescript/DocumentSnapshot.ts +++ b/packages/language-server/src/plugins/typescript/DocumentSnapshot.ts @@ -266,7 +266,7 @@ function preprocessSvelteFile(document: Document, options: SvelteSnapshotOptions export class SvelteDocumentSnapshot implements DocumentSnapshot { private mapper?: DocumentMapper; private lineOffsets?: number[]; - private url = pathToUrl(this.filePath); + private url = this.fileUrl; version = this.parent.version; isSvelte5Plus = Number(this.svelteVersion?.split('.')[0]) >= 5; @@ -281,7 +281,11 @@ export class SvelteDocumentSnapshot implements DocumentSnapshot { private readonly exportedNames: IExportedNames, private readonly tsxMap?: EncodedSourceMap, private readonly htmlAst?: TemplateNode - ) {} + ) { } + + get fileUrl() { + return this.parent.getURL() || ''; + } get filePath() { return this.parent.getFilePath() || ''; diff --git a/packages/language-server/src/utils.ts b/packages/language-server/src/utils.ts index a79c49999..2caca64a4 100644 --- a/packages/language-server/src/utils.ts +++ b/packages/language-server/src/utils.ts @@ -28,14 +28,18 @@ export function clamp(num: number, min: number, max: number): number { export function urlToPath(stringUrl: string): string | null { const url = URI.parse(stringUrl); - if (url.scheme !== 'file') { + if (url.scheme === 'http' || url.scheme === 'https') { return null; } return url.fsPath.replace(/\\/g, '/'); } -export function pathToUrl(path: string) { - return URI.file(path).toString(); +export function pathToUrl(path: string, scheme?: string) { + const baseUri = URI.file(path); + if (scheme) { + return baseUri.with({ scheme: scheme }).toString(); + } + return baseUri.toString(); } /** diff --git a/packages/svelte-vscode/src/extension.ts b/packages/svelte-vscode/src/extension.ts index 267d4772c..f62f27308 100644 --- a/packages/svelte-vscode/src/extension.ts +++ b/packages/svelte-vscode/src/extension.ts @@ -151,7 +151,7 @@ export function activateSvelteLanguageServer(context: ExtensionContext) { } const clientOptions: LanguageClientOptions = { - documentSelector: [{ scheme: 'file', language: 'svelte' }], + documentSelector: [{ scheme: '*', language: 'svelte' }], revealOutputChannelOn: RevealOutputChannelOn.Never, synchronize: { // TODO deprecated, rework upon next VS Code minimum version bump