Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow embedded languages to utilise Svelte Intellisense in VSCode #2611

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 7 additions & 3 deletions packages/language-server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
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