Skip to content

Commit 255a4a8

Browse files
authored
Merge pull request #146 from ayame113/master
2 parents 9abd5b6 + 37a9398 commit 255a4a8

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/adapters/definition-adapter.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type * as atomIde from "atom-ide-base"
22
import Convert from "../convert"
33
import * as Utils from "../utils"
4-
import { LanguageClientConnection, Location, ServerCapabilities } from "../languageclient"
4+
import { LanguageClientConnection, Location, LocationLink, ServerCapabilities } from "../languageclient"
55
import { Point, TextEditor, Range } from "atom"
66

77
/**
@@ -68,10 +68,17 @@ export default class DefinitionAdapter {
6868
* @param locationResult Either a single {Location} object or an {Array} of {Locations}.
6969
* @returns An {Array} of {Location}s or {null} if the locationResult was null.
7070
*/
71-
public static normalizeLocations(locationResult: Location | Location[]): Location[] | null {
71+
public static normalizeLocations(
72+
locationResult: Location | Location[] | LocationLink[] | null
73+
): Location[] | LocationLink[] | null {
7274
if (locationResult == null) {
75+
// TODO use ===
7376
return null
7477
}
78+
// TODO `d.targetRange.start` never becomes `null` according to the types
79+
if (isLocationLinkArray(locationResult)) {
80+
return locationResult.filter((d) => d.targetRange.start != null)
81+
}
7582
return (Array.isArray(locationResult) ? locationResult : [locationResult]).filter((d) => d.range.start != null)
7683
}
7784

@@ -82,7 +89,18 @@ export default class DefinitionAdapter {
8289
* @param languageName The name of the language these objects are written in.
8390
* @returns An {Array} of {Definition}s that represented the converted {Location}s.
8491
*/
85-
public static convertLocationsToDefinitions(locations: Location[], languageName: string): atomIde.Definition[] {
92+
public static convertLocationsToDefinitions(
93+
locations: Location[] | LocationLink[],
94+
languageName: string
95+
): atomIde.Definition[] {
96+
if (isLocationLinkArray(locations)) {
97+
return locations.map((d) => ({
98+
path: Convert.uriToPath(d.targetUri),
99+
position: Convert.positionToPoint(d.targetRange.start),
100+
range: Range.fromObject(Convert.lsRangeToAtomRange(d.targetRange)),
101+
language: languageName,
102+
}))
103+
}
86104
return locations.map((d) => ({
87105
path: Convert.uriToPath(d.uri),
88106
position: Convert.positionToPoint(d.range.start),
@@ -91,3 +109,7 @@ export default class DefinitionAdapter {
91109
}))
92110
}
93111
}
112+
113+
function isLocationLinkArray(value: any): value is LocationLink[] {
114+
return Array.isArray(value) && LocationLink.is(value[0])
115+
}

lib/languageclient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ export class LanguageClientConnection extends EventEmitter {
343343
* symbol are required.
344344
* @returns A {Promise} containing either a single {Location} or an {Array} of many {Location}s.
345345
*/
346-
public gotoDefinition(params: lsp.TextDocumentPositionParams): Promise<lsp.Location | lsp.Location[]> {
346+
public gotoDefinition(
347+
params: lsp.TextDocumentPositionParams
348+
): Promise<lsp.Location | lsp.Location[] | lsp.LocationLink[] | null> {
347349
return this._sendRequest("textDocument/definition", params)
348350
}
349351

0 commit comments

Comments
 (0)