mirror of
https://github.com/c-cube/linol.git
synced 2025-12-10 05:04:00 -05:00
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import outdent from "outdent";
|
|
import * as Protocol from "vscode-languageserver-protocol";
|
|
import * as Types from "vscode-languageserver-types";
|
|
import { isNotNullable } from "../src/utils";
|
|
import * as LanguageServer from "./../src/LanguageServer";
|
|
import { testUri } from "./../src/LanguageServer";
|
|
|
|
describe("textDocument/definition", () => {
|
|
let languageServer: LanguageServer.LanguageServer;
|
|
|
|
function openDocument(source: string) {
|
|
languageServer.sendNotification(
|
|
Protocol.DidOpenTextDocumentNotification.type,
|
|
{
|
|
textDocument: Types.TextDocumentItem.create(
|
|
testUri("test.ml"),
|
|
"ocaml",
|
|
0,
|
|
source,
|
|
),
|
|
},
|
|
);
|
|
}
|
|
|
|
async function queryDefinition(position: Types.Position) {
|
|
let result = await languageServer.sendRequest(
|
|
Protocol.DefinitionRequest.type,
|
|
{
|
|
textDocument: Types.TextDocumentIdentifier.create(testUri("test.ml")),
|
|
position,
|
|
},
|
|
);
|
|
|
|
if (result === null) return [];
|
|
|
|
result = Array.isArray(result) ? result : [result];
|
|
|
|
return result
|
|
.map((location) => (Types.Location.is(location) ? location : null))
|
|
.filter(isNotNullable);
|
|
}
|
|
|
|
beforeEach(async () => {
|
|
languageServer = await LanguageServer.startAndInitialize();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await LanguageServer.exit(languageServer);
|
|
});
|
|
|
|
it("returns location of a definition", async () => {
|
|
openDocument(outdent`
|
|
let x = 43
|
|
|
|
let () =
|
|
print_int x
|
|
`);
|
|
|
|
const result = await queryDefinition(Types.Position.create(3, 12));
|
|
|
|
expect(result.length).toBe(1);
|
|
expect(result[0].range).toMatchObject({
|
|
end: { character: 4, line: 0 },
|
|
start: { character: 4, line: 0 },
|
|
});
|
|
expect(result[0].uri).toEqualUri(testUri("test.ml"));
|
|
});
|
|
});
|