Skip to content

Commit

Permalink
Only apply required changes to let non-file type URIs work with the e…
Browse files Browse the repository at this point in the history
…xtension
  • Loading branch information
jpedley committed Nov 30, 2024
1 parent fda35fe commit 26a4f37
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() || '';
Expand Down
7 changes: 5 additions & 2 deletions packages/language-server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ 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) {
export function pathToUrl(path: string, scheme?: string) {
const baseUri = URI.file(path);
if (scheme)
return baseUri.with({ scheme: scheme }).toString();
return URI.file(path).toString();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26a4f37

Please sign in to comment.