use LocationLink on getSymbolLocations
This commit is contained in:
parent
9bac05ab03
commit
bbfe46c4aa
1 changed files with 19 additions and 10 deletions
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { TextDocument } from 'coc.nvim'
|
||||
import { LocationLink, TextDocument } from 'coc.nvim'
|
||||
import { DefinitionProvider, CancellationToken, Definition, Location, Position, DefinitionLink, ImplementationProvider, TypeDefinitionProvider } from 'coc.nvim'
|
||||
import * as Proto from '../protocol'
|
||||
import { ITypeScriptServiceClient } from '../typescriptService'
|
||||
|
@ -17,7 +17,7 @@ export default class TypeScriptDefinitionProvider implements DefinitionProvider,
|
|||
document: TextDocument,
|
||||
position: Position,
|
||||
token: CancellationToken
|
||||
): Promise<Location[] | undefined> {
|
||||
): Promise<Location[] | LocationLink[] | undefined> {
|
||||
const filepath = this.client.toPath(document.uri)
|
||||
if (!filepath) {
|
||||
return undefined
|
||||
|
@ -29,12 +29,21 @@ export default class TypeScriptDefinitionProvider implements DefinitionProvider,
|
|||
)
|
||||
try {
|
||||
const response = await this.client.execute(definitionType, args, token)
|
||||
const locations: Proto.FileSpan[] = (response.type == 'response' && response.body) || []
|
||||
return locations.map(location =>
|
||||
typeConverters.Location.fromTextSpan(
|
||||
this.client.toResource(location.file),
|
||||
location
|
||||
)
|
||||
if (response.type !== 'response' || !response.body) {
|
||||
return undefined
|
||||
}
|
||||
const locations: Proto.FileSpanWithContext[] = (response.type == 'response' && response.body) || []
|
||||
return locations.map(location => {
|
||||
const target = typeConverters.Location.fromTextSpan(this.client.toResource(location.file), location)
|
||||
if (location.contextStart && location.contextEnd) {
|
||||
return {
|
||||
targetRange: typeConverters.Range.fromLocations(location.contextStart, location.contextEnd),
|
||||
targetUri: target.uri,
|
||||
targetSelectionRange: target.range,
|
||||
} as any
|
||||
}
|
||||
return target
|
||||
}
|
||||
)
|
||||
} catch {
|
||||
return []
|
||||
|
@ -84,14 +93,14 @@ export default class TypeScriptDefinitionProvider implements DefinitionProvider,
|
|||
public provideTypeDefinition(
|
||||
document: TextDocument,
|
||||
position: Position,
|
||||
token: CancellationToken): Promise<Definition> {
|
||||
token: CancellationToken): Promise<Definition | DefinitionLink[]> {
|
||||
return this.getSymbolLocations('typeDefinition', document, position, token)
|
||||
}
|
||||
|
||||
public provideImplementation(
|
||||
document: TextDocument,
|
||||
position: Position,
|
||||
token: CancellationToken): Promise<Definition> {
|
||||
token: CancellationToken): Promise<Definition | DefinitionLink[]> {
|
||||
return this.getSymbolLocations('implementation', document, position, token)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue