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.
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
* 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 { DefinitionProvider, CancellationToken, Definition, Location, Position, DefinitionLink, ImplementationProvider, TypeDefinitionProvider } from 'coc.nvim'
|
||||||
import * as Proto from '../protocol'
|
import * as Proto from '../protocol'
|
||||||
import { ITypeScriptServiceClient } from '../typescriptService'
|
import { ITypeScriptServiceClient } from '../typescriptService'
|
||||||
|
@ -17,7 +17,7 @@ export default class TypeScriptDefinitionProvider implements DefinitionProvider,
|
||||||
document: TextDocument,
|
document: TextDocument,
|
||||||
position: Position,
|
position: Position,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
): Promise<Location[] | undefined> {
|
): Promise<Location[] | LocationLink[] | undefined> {
|
||||||
const filepath = this.client.toPath(document.uri)
|
const filepath = this.client.toPath(document.uri)
|
||||||
if (!filepath) {
|
if (!filepath) {
|
||||||
return undefined
|
return undefined
|
||||||
|
@ -29,12 +29,21 @@ export default class TypeScriptDefinitionProvider implements DefinitionProvider,
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const response = await this.client.execute(definitionType, args, token)
|
const response = await this.client.execute(definitionType, args, token)
|
||||||
const locations: Proto.FileSpan[] = (response.type == 'response' && response.body) || []
|
if (response.type !== 'response' || !response.body) {
|
||||||
return locations.map(location =>
|
return undefined
|
||||||
typeConverters.Location.fromTextSpan(
|
}
|
||||||
this.client.toResource(location.file),
|
const locations: Proto.FileSpanWithContext[] = (response.type == 'response' && response.body) || []
|
||||||
location
|
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 {
|
} catch {
|
||||||
return []
|
return []
|
||||||
|
@ -84,14 +93,14 @@ export default class TypeScriptDefinitionProvider implements DefinitionProvider,
|
||||||
public provideTypeDefinition(
|
public provideTypeDefinition(
|
||||||
document: TextDocument,
|
document: TextDocument,
|
||||||
position: Position,
|
position: Position,
|
||||||
token: CancellationToken): Promise<Definition> {
|
token: CancellationToken): Promise<Definition | DefinitionLink[]> {
|
||||||
return this.getSymbolLocations('typeDefinition', document, position, token)
|
return this.getSymbolLocations('typeDefinition', document, position, token)
|
||||||
}
|
}
|
||||||
|
|
||||||
public provideImplementation(
|
public provideImplementation(
|
||||||
document: TextDocument,
|
document: TextDocument,
|
||||||
position: Position,
|
position: Position,
|
||||||
token: CancellationToken): Promise<Definition> {
|
token: CancellationToken): Promise<Definition | DefinitionLink[]> {
|
||||||
return this.getSymbolLocations('implementation', document, position, token)
|
return this.getSymbolLocations('implementation', document, position, token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue