-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(library | ||
(name declaration_files)) |
1 change: 1 addition & 0 deletions
1
ocaml-lsp-server/test/e2e/__tests__/declaration_files/dune-project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(lang dune 2.5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let x = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
val x : int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let y = Lib.x |
71 changes: 71 additions & 0 deletions
71
ocaml-lsp-server/test/e2e/__tests__/textDocument-declaration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { promises as fs } from "fs"; | ||
import * as path from "path"; | ||
import * as child_process from "child_process"; | ||
import * as LanguageServer from "./../src/LanguageServer"; | ||
import * as Types from "vscode-languageserver-types"; | ||
import { testUri, toEqualUri } from "./../src/LanguageServer"; | ||
expect.extend({ | ||
toEqualUri, | ||
}); | ||
declare global { | ||
namespace jest { | ||
interface Matchers<R> { | ||
toEqualUri(uri: string): R; | ||
} | ||
} | ||
} | ||
|
||
describe("textDocument/declaration", () => { | ||
let languageServer = null; | ||
|
||
let testWorkspacePath = path.join(__dirname, "declaration_files/"); | ||
|
||
let createPathForFile = (filename: string) => | ||
path.join(testWorkspacePath, filename); | ||
|
||
beforeEach(async () => { | ||
languageServer = await LanguageServer.startAndInitialize(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await LanguageServer.exit(languageServer); | ||
languageServer = null; | ||
}); | ||
|
||
async function openDocument(filepath) { | ||
let source = await fs.readFile(filepath); | ||
await languageServer.sendNotification("textDocument/didOpen", { | ||
textDocument: Types.TextDocumentItem.create( | ||
testUri(filepath), | ||
"ocaml", | ||
0, | ||
source.toString(), | ||
), | ||
}); | ||
} | ||
|
||
async function queryDeclaration(filepath, position) { | ||
return await languageServer.sendRequest("textDocument/declaration", { | ||
textDocument: Types.TextDocumentIdentifier.create(testUri(filepath)), | ||
position, | ||
}); | ||
} | ||
|
||
it("returns location of a declaration", async () => { | ||
child_process.execSync("dune build", { cwd: testWorkspacePath }); | ||
|
||
await openDocument(createPathForFile("main.ml")); | ||
|
||
let result = await queryDeclaration( | ||
createPathForFile("main.ml"), | ||
Types.Position.create(0, 13), | ||
); | ||
|
||
expect(result.length).toBe(1); | ||
expect(result[0].range).toMatchObject({ | ||
end: { character: 0, line: 0 }, | ||
start: { character: 0, line: 0 }, | ||
}); | ||
expect(result[0].uri).toEqualUri(testUri(createPathForFile("lib.ml"))); | ||
}); | ||
}); |