Skip to content

Commit

Permalink
Merge pull request #150 from ayame113/master
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored May 1, 2021
2 parents ffbe675 + 304e100 commit 5c30200
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 92 deletions.
3 changes: 3 additions & 0 deletions lib/adapters/code-action-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export default class CodeActionAdapter {

const params = CodeActionAdapter.createCodeActionParams(linterAdapter, editor, range, diagnostics)
const actions = await connection.codeAction(params)
if (actions === null) {
return []
}
return actions.map((action) => CodeActionAdapter.createCodeAction(action, connection))
}

Expand Down
5 changes: 4 additions & 1 deletion lib/adapters/code-highlight-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ export default class CodeHighlightAdapter {
serverCapabilities: ServerCapabilities,
editor: TextEditor,
position: Point
): Promise<Range[] | null> {
): Promise<Range[]> {
assert(serverCapabilities.documentHighlightProvider, "Must have the documentHighlight capability")
const highlights = await connection.documentHighlight(Convert.editorToTextDocumentPositionParams(editor, position))
if (highlights === null) {
return []
}
return highlights.map((highlight) => {
return Convert.lsRangeToAtomRange(highlight.range)
})
Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/outline-view-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class OutlineViewAdapter {
connection.documentSymbol({ textDocument: Convert.editorToTextDocumentIdentifier(editor) }, cancellationToken)
)

if (results.length === 0) {
if (results === null || results.length === 0) {
return {
outlineTrees: [],
}
Expand Down
2 changes: 1 addition & 1 deletion lib/auto-languageclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ export default class AutoLanguageClient {
* `didChangeWatchedFiles` message filtering, override for custom logic.
*
* @param filePath Path of a file that has changed in the project path
* @returns `false` => message will not be sent to the language server
* @returns `false` => message will not be sent to the language server
*/
protected filterChangeWatchedFiles(_filePath: string): boolean {
return true
Expand Down
111 changes: 58 additions & 53 deletions lib/languageclient.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"eslint-plugin-chai-friendly": "^0.6.0",
"mocha": "^8.3.2",
"mocha-appveyor-reporter": "^0.4.2",
"prettier-config-atomic": "^2.0.2",
"prettier-config-atomic": "^2.0.3",
"shx": "^0.3.3",
"sinon": "^10.0.0",
"typescript": "~4.2.4"
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 28 additions & 28 deletions test/languageclient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ describe("LanguageClientConnection", () => {
await lc.initialize(params)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("initialize")
expect(lc._sendRequest.getCall(0).args[0].method).equals("initialize")
expect(lc._sendRequest.getCall(0).args[1]).equals(params)
})

it("sends a request for shutdown", async () => {
await lc.shutdown()

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("shutdown")
expect(lc._sendRequest.getCall(0).args[0].method).equals("shutdown")
})

it("sends a request for completion", async () => {
await lc.completion(textDocumentPositionParams)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/completion")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/completion")
expect(lc._sendRequest.getCall(0).args[1]).equals(textDocumentPositionParams)
})

Expand All @@ -61,55 +61,55 @@ describe("LanguageClientConnection", () => {
await lc.completionItemResolve(completionItem)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("completionItem/resolve")
expect(lc._sendRequest.getCall(0).args[0].method).equals("completionItem/resolve")
expect(lc._sendRequest.getCall(0).args[1]).equals(completionItem)
})

it("sends a request for hover", async () => {
await lc.hover(textDocumentPositionParams)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/hover")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/hover")
expect(lc._sendRequest.getCall(0).args[1]).equals(textDocumentPositionParams)
})

it("sends a request for signatureHelp", async () => {
await lc.signatureHelp(textDocumentPositionParams)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/signatureHelp")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/signatureHelp")
expect(lc._sendRequest.getCall(0).args[1]).equals(textDocumentPositionParams)
})

it("sends a request for gotoDefinition", async () => {
await lc.gotoDefinition(textDocumentPositionParams)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/definition")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/definition")
expect(lc._sendRequest.getCall(0).args[1]).equals(textDocumentPositionParams)
})

it("sends a request for findReferences", async () => {
await lc.findReferences(textDocumentPositionParams)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/references")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/references")
expect(lc._sendRequest.getCall(0).args[1]).equals(textDocumentPositionParams)
})

it("sends a request for documentHighlight", async () => {
await lc.documentHighlight(textDocumentPositionParams)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/documentHighlight")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/documentHighlight")
expect(lc._sendRequest.getCall(0).args[1]).equals(textDocumentPositionParams)
})

it("sends a request for documentSymbol", async () => {
await lc.documentSymbol(textDocumentPositionParams)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/documentSymbol")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/documentSymbol")
expect(lc._sendRequest.getCall(0).args[1]).equals(textDocumentPositionParams)
})

Expand All @@ -118,7 +118,7 @@ describe("LanguageClientConnection", () => {
await lc.workspaceSymbol(params)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("workspace/symbol")
expect(lc._sendRequest.getCall(0).args[0].method).equals("workspace/symbol")
expect(lc._sendRequest.getCall(0).args[1]).equals(params)
})

Expand All @@ -134,7 +134,7 @@ describe("LanguageClientConnection", () => {
await lc.codeAction(params)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/codeAction")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/codeAction")
expect(lc._sendRequest.getCall(0).args[1]).equals(params)
})

Expand All @@ -145,7 +145,7 @@ describe("LanguageClientConnection", () => {
await lc.codeLens(params)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/codeLens")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/codeLens")
expect(lc._sendRequest.getCall(0).args[1]).equals(params)
})

Expand All @@ -159,7 +159,7 @@ describe("LanguageClientConnection", () => {
await lc.codeLensResolve(params)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("codeLens/resolve")
expect(lc._sendRequest.getCall(0).args[0].method).equals("codeLens/resolve")
expect(lc._sendRequest.getCall(0).args[1]).equals(params)
})

Expand All @@ -170,7 +170,7 @@ describe("LanguageClientConnection", () => {
await lc.documentLink(params)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/documentLink")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/documentLink")
expect(lc._sendRequest.getCall(0).args[1]).equals(params)
})

Expand All @@ -185,7 +185,7 @@ describe("LanguageClientConnection", () => {
await lc.documentLinkResolve(params)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("documentLink/resolve")
expect(lc._sendRequest.getCall(0).args[0].method).equals("documentLink/resolve")
expect(lc._sendRequest.getCall(0).args[1]).equals(params)
})

Expand All @@ -197,7 +197,7 @@ describe("LanguageClientConnection", () => {
await lc.documentFormatting(params)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/formatting")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/formatting")
expect(lc._sendRequest.getCall(0).args[1]).equals(params)
})

Expand All @@ -213,7 +213,7 @@ describe("LanguageClientConnection", () => {
await lc.documentRangeFormatting(params)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/rangeFormatting")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/rangeFormatting")
expect(lc._sendRequest.getCall(0).args[1]).equals(params)
})

Expand All @@ -227,7 +227,7 @@ describe("LanguageClientConnection", () => {
await lc.documentOnTypeFormatting(params)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/onTypeFormatting")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/onTypeFormatting")
expect(lc._sendRequest.getCall(0).args[1]).equals(params)
})

Expand All @@ -240,7 +240,7 @@ describe("LanguageClientConnection", () => {
await lc.rename(params)

expect(lc._sendRequest.called).equals(true)
expect(lc._sendRequest.getCall(0).args[0]).equals("textDocument/rename")
expect(lc._sendRequest.getCall(0).args[0].method).equals("textDocument/rename")
expect(lc._sendRequest.getCall(0).args[1]).equals(params)
})
})
Expand Down Expand Up @@ -268,15 +268,15 @@ describe("LanguageClientConnection", () => {
lc.exit()

expect(lc._sendNotification.called).equals(true)
expect(lc._sendNotification.getCall(0).args[0]).equals("exit")
expect(lc._sendNotification.getCall(0).args[0].method).equals("exit")
expect(lc._sendNotification.getCall(0).args.length).equals(1)
})

it("initialized sends notification", () => {
lc.initialized()

expect(lc._sendNotification.called).equals(true)
expect(lc._sendNotification.getCall(0).args[0]).equals("initialized")
expect(lc._sendNotification.getCall(0).args[0].method).equals("initialized")
const expected: ls.InitializedParams = {}
expect(lc._sendNotification.getCall(0).args[1]).to.deep.equal(expected)
})
Expand All @@ -288,7 +288,7 @@ describe("LanguageClientConnection", () => {
lc.didChangeConfiguration(params)

expect(lc._sendNotification.called).equals(true)
expect(lc._sendNotification.getCall(0).args[0]).equals("workspace/didChangeConfiguration")
expect(lc._sendNotification.getCall(0).args[0].method).equals("workspace/didChangeConfiguration")
expect(lc._sendNotification.getCall(0).args[1]).equals(params)
})

Expand All @@ -299,7 +299,7 @@ describe("LanguageClientConnection", () => {
lc.didOpenTextDocument(params)

expect(lc._sendNotification.called).equals(true)
expect(lc._sendNotification.getCall(0).args[0]).equals("textDocument/didOpen")
expect(lc._sendNotification.getCall(0).args[0].method).equals("textDocument/didOpen")
expect(lc._sendNotification.getCall(0).args[1]).equals(params)
})

Expand All @@ -311,7 +311,7 @@ describe("LanguageClientConnection", () => {
lc.didChangeTextDocument(params)

expect(lc._sendNotification.called).equals(true)
expect(lc._sendNotification.getCall(0).args[0]).equals("textDocument/didChange")
expect(lc._sendNotification.getCall(0).args[0].method).equals("textDocument/didChange")
expect(lc._sendNotification.getCall(0).args[1]).equals(params)
})

Expand All @@ -322,7 +322,7 @@ describe("LanguageClientConnection", () => {
lc.didCloseTextDocument(params)

expect(lc._sendNotification.called).equals(true)
expect(lc._sendNotification.getCall(0).args[0]).equals("textDocument/didClose")
expect(lc._sendNotification.getCall(0).args[0].method).equals("textDocument/didClose")
expect(lc._sendNotification.getCall(0).args[1]).equals(params)
})

Expand All @@ -333,7 +333,7 @@ describe("LanguageClientConnection", () => {
lc.didSaveTextDocument(params)

expect(lc._sendNotification.called).equals(true)
expect(lc._sendNotification.getCall(0).args[0]).equals("textDocument/didSave")
expect(lc._sendNotification.getCall(0).args[0].method).equals("textDocument/didSave")
expect(lc._sendNotification.getCall(0).args[1]).equals(params)
})

Expand All @@ -342,7 +342,7 @@ describe("LanguageClientConnection", () => {
lc.didChangeWatchedFiles(params)

expect(lc._sendNotification.called).equals(true)
expect(lc._sendNotification.getCall(0).args[0]).equals("workspace/didChangeWatchedFiles")
expect(lc._sendNotification.getCall(0).args[0].method).equals("workspace/didChangeWatchedFiles")
expect(lc._sendNotification.getCall(0).args[1]).equals(params)
})
})
Expand Down

0 comments on commit 5c30200

Please sign in to comment.