@rank-lang/lsp 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/dist/features/completion.d.ts +4 -0
- package/dist/features/completion.js +23 -0
- package/dist/features/definition.d.ts +4 -0
- package/dist/features/definition.js +32 -0
- package/dist/features/diagnostics.d.ts +3 -0
- package/dist/features/diagnostics.js +133 -0
- package/dist/features/hover.d.ts +4 -0
- package/dist/features/hover.js +75 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +57 -0
- package/dist/session.d.ts +14 -0
- package/dist/session.js +167 -0
- package/dist/util/convert.d.ts +6 -0
- package/dist/util/convert.js +40 -0
- package/dist/util/stdlib-hover.d.ts +4 -0
- package/dist/util/stdlib-hover.js +109 -0
- package/dist/util/type-symbols.d.ts +13 -0
- package/dist/util/type-symbols.js +118 -0
- package/package.json +41 -0
- package/src/features/completion.ts +37 -0
- package/src/features/definition.ts +49 -0
- package/src/features/diagnostics.ts +195 -0
- package/src/features/hover.ts +127 -0
- package/src/server.ts +73 -0
- package/src/session.ts +224 -0
- package/src/util/convert.ts +54 -0
- package/src/util/stdlib-hover.ts +178 -0
- package/src/util/type-symbols.ts +165 -0
- package/test/convert.test.ts +46 -0
- package/test/editor-features.test.ts +1167 -0
- package/test/session.test.ts +58 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +10 -0
- package/vitest.config.ts +36 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
import { checkModuleTypes } from "@rank-lang/compiler";
|
|
5
|
+
import { describe, expect, test } from "vitest";
|
|
6
|
+
|
|
7
|
+
import { ProjectSession } from "../src/session.ts";
|
|
8
|
+
|
|
9
|
+
function examplePath(...segments: string[]): string {
|
|
10
|
+
return fileURLToPath(new URL(`../../../examples/${segments.join("/")}`, import.meta.url));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe("ProjectSession", () => {
|
|
14
|
+
test("loads standalone files without a manifest", async () => {
|
|
15
|
+
const session = new ProjectSession();
|
|
16
|
+
const filePath = examplePath("env-inputs", "main.rank");
|
|
17
|
+
const graph = await session.getModuleGraph(filePath);
|
|
18
|
+
|
|
19
|
+
expect(graph).not.toBeNull();
|
|
20
|
+
|
|
21
|
+
if (!graph) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
expect(session.getLoadedModule(graph, filePath)?.filePath).toBe(path.resolve(filePath));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("loads manifest-backed files from the active file path", async () => {
|
|
29
|
+
const session = new ProjectSession();
|
|
30
|
+
const filePath = examplePath("test-fixtures", "main.rank");
|
|
31
|
+
const graph = await session.getModuleGraph(filePath);
|
|
32
|
+
|
|
33
|
+
expect(graph).not.toBeNull();
|
|
34
|
+
|
|
35
|
+
if (!graph) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
expect(session.getLoadedModule(graph, filePath)?.filePath).toBe(path.resolve(filePath));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("prefers sibling main.rank for imported helper modules", async () => {
|
|
43
|
+
const session = new ProjectSession();
|
|
44
|
+
const filePath = examplePath("multi-env-app", "base.rank");
|
|
45
|
+
const entryPath = examplePath("multi-env-app", "main.rank");
|
|
46
|
+
const graph = await session.getModuleGraph(filePath);
|
|
47
|
+
|
|
48
|
+
expect(graph).not.toBeNull();
|
|
49
|
+
|
|
50
|
+
if (!graph) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
expect(session.getLoadedModule(graph, filePath)?.filePath).toBe(path.resolve(filePath));
|
|
55
|
+
expect(graph.modules[graph.entryModulePath]?.filePath).toBe(path.resolve(entryPath));
|
|
56
|
+
expect(checkModuleTypes(graph).find((diagnostic) => diagnostic.code === "TYP030")).toBeUndefined();
|
|
57
|
+
});
|
|
58
|
+
});
|
package/tsconfig.json
ADDED
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { defineConfig } from "vitest/config";
|
|
4
|
+
|
|
5
|
+
function stripQuery(id: string): string {
|
|
6
|
+
const queryIndex = id.search(/[?#]/);
|
|
7
|
+
return queryIndex >= 0 ? id.slice(0, queryIndex) : id;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function fallbackMissingJsToTs() {
|
|
11
|
+
return {
|
|
12
|
+
name: "rank-fallback-missing-js-to-ts",
|
|
13
|
+
resolveId(source: string, importer?: string) {
|
|
14
|
+
if (!importer || !source.startsWith(".") || !source.endsWith(".js")) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const importerPath = stripQuery(importer);
|
|
19
|
+
if (!path.isAbsolute(importerPath)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const jsPath = path.resolve(path.dirname(importerPath), stripQuery(source));
|
|
24
|
+
if (existsSync(jsPath)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const tsPath = `${jsPath.slice(0, -3)}.ts`;
|
|
29
|
+
return existsSync(tsPath) ? tsPath : null;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
plugins: [fallbackMissingJsToTs()],
|
|
36
|
+
});
|