Файли
openidea/src/platform/virtualDocs.test.ts
T
l0ng-ai d54ef98a59 fix(lsp): open library classes behind jar: URIs (#1048)
The official Kotlin LSP answers navigation into a dependency with a
`jar:///…/lib.jar!/pkg/Name.class` URI but does not serve its contents through
`workspace/textDocumentContent`, so opening the target failed with "no
language server provides the contents of jar:…", locally and remotely.

`jar:` URIs are now resolved by the backend, where the jars are:
- An entry that is not a class (a sources jar entry, a resource) is read from
  its archive.
- A class is shown as its source from the artifact's `-sources.jar` in the
  Maven repository or the Gradle cache (`Name.java`/`Name.kt`, an inner
  class's outer file, a `FileKt` facade's `File.kt`, a `@file:JvmName`
  file); Go to Declaration then lands on the declaration of the name it was
  invoked on.
- Otherwise the server's `decompile` command is used when it offers one, and
  the error says that neither a source nor a decompiler is available.
- Library tabs name the archive and package (`spring-boot-3.5.16.jar ›
  org.springframework.boot`).

Fixes #982
2026-11-03 22:04:05 +08:00

41 рядки
2.1 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
import { describe, expect, it } from "vitest";
import { isVirtualUri, virtualContainer, virtualName, virtualParent } from "./virtualDocs";
import { basename, dirname, relativeDir, relativePath } from "./project";
const JDT =
"jdt://contents/spring-boot-4.1.1.jar/org.springframework.boot/SpringApplication.class?=demo/%5C/m2%5C/spring-boot-4.1.1.jar%3Corg.springframework.boot%28SpringApplication.class";
describe("virtual document URIs", () => {
it("tells URIs from file paths", () => {
expect(isVirtualUri(JDT)).toBe(true);
expect(isVirtualUri("untitled:Untitled-1")).toBe(true);
expect(isVirtualUri("/Users/me/a.java")).toBe(false);
expect(isVirtualUri("C:\\src\\a.java")).toBe(false);
expect(isVirtualUri("file:///a.java")).toBe(false);
expect(isVirtualUri(null)).toBe(false);
});
it("names and locates library classes", () => {
expect(virtualName(JDT)).toBe("SpringApplication.class");
expect(virtualParent(JDT)).toBe("jdt://contents/spring-boot-4.1.1.jar/org.springframework.boot");
expect(virtualContainer(JDT)).toBe("spring-boot-4.1.1.jar › org.springframework.boot");
// `jar:` targets (official Kotlin LSP, sources jars), in both URI forms.
for (const prefix of ["jar:///", "jar:file:///"])
expect(
virtualContainer(
`${prefix}home/me/.m2/repository/spring-boot-3.5.16-sources.jar!/org/springframework/boot/SpringApplicationExtensions.kt`,
),
).toBe("spring-boot-3.5.16-sources.jar › org.springframework.boot");
expect(virtualContainer("jar:///tmp/my%20libs/a.jar!/Root.class")).toBe("a.jar");
expect(virtualName("jar:///tmp/a.jar!/org/x/Y.class")).toBe("Y.class");
});
it("makes path helpers URI-aware", () => {
expect(basename(JDT)).toBe("SpringApplication.class");
expect(basename(dirname(JDT))).toBe("org.springframework.boot");
expect(relativePath("/p", JDT)).toBe("spring-boot-4.1.1.jar › org.springframework.boot › SpringApplication.class");
expect(relativeDir("/p", JDT)).toBe("spring-boot-4.1.1.jar › org.springframework.boot");
expect(relativePath("/p", "/p/src/A.java")).toBe("src/A.java");
});
});