Skip to content

Commit a98cf0b

Browse files
committed
fix: use cache file uri as fallback for unrecognised saf uri
1 parent 7d33563 commit a98cf0b

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

bun.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cm/lsp/clientManager.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,23 @@ export class LspClientManager {
160160
if (!servers.length) return [];
161161

162162
// Normalize the document URI for LSP (convert content:// to file://)
163-
const normalizedUri = normalizeDocumentUri(originalUri);
163+
let normalizedUri = normalizeDocumentUri(originalUri);
164164
if (!normalizedUri) {
165-
console.warn(`Cannot normalize document URI for LSP: ${originalUri}`);
166-
return [];
165+
// Fall back to cache file path for unrecognized URIs
166+
// This allows LSP to work with any file system provider using the local cache
167+
const cacheFile = file?.cacheFile;
168+
if (cacheFile && typeof cacheFile === "string") {
169+
normalizedUri = buildFileUri(cacheFile.replace(/^file:\/\//, ""));
170+
if (normalizedUri) {
171+
console.info(
172+
`LSP using cache path for unrecognized URI: ${originalUri} -> ${normalizedUri}`,
173+
);
174+
}
175+
}
176+
if (!normalizedUri) {
177+
console.warn(`Cannot normalize document URI for LSP: ${originalUri}`);
178+
return [];
179+
}
167180
}
168181

169182
const lspExtensions: Extension[] = [];
@@ -232,12 +245,18 @@ export class LspClientManager {
232245
const effectiveLang = safeString(languageId ?? languageName).toLowerCase();
233246
if (!effectiveLang || !view) return false;
234247

235-
const normalizedUri = normalizeDocumentUri(originalUri);
248+
let normalizedUri = normalizeDocumentUri(originalUri);
236249
if (!normalizedUri) {
237-
console.warn(
238-
`Cannot normalize document URI for formatting: ${originalUri}`,
239-
);
240-
return false;
250+
const cacheFile = file?.cacheFile;
251+
if (cacheFile && typeof cacheFile === "string") {
252+
normalizedUri = buildFileUri(cacheFile.replace(/^file:\/\//, ""));
253+
}
254+
if (!normalizedUri) {
255+
console.warn(
256+
`Cannot normalize document URI for formatting: ${originalUri}`,
257+
);
258+
return false;
259+
}
241260
}
242261

243262
const servers = serverRegistry.getServersForLanguage(effectiveLang);

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ interface AcodeFile {
8989
uri?: string;
9090
name?: string;
9191
session?: unknown;
92+
cacheFile?: string;
9293
[key: string]: unknown;
9394
}
9495

0 commit comments

Comments
 (0)