Skip to content

Commit 16bdaaa

Browse files
author
Andy Hanson
committed
Fix positionToLineOffset conversion for getImplementation
1 parent abc30b2 commit 16bdaaa

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/server/session.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -484,18 +484,20 @@ namespace ts.server {
484484

485485
private getImplementation(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.FileSpan[] | ImplementationLocation[] {
486486
const { file, project } = this.getFileAndProject(args);
487-
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
488-
const position = this.getPosition(args, scriptInfo);
487+
const position = this.getPosition(args, project.getScriptInfoForNormalizedPath(file));
489488
const implementations = project.getLanguageService().getImplementationAtPosition(file, position);
490489
if (!implementations) {
491490
return [];
492491
}
493492
if (simplifiedResult) {
494-
return implementations.map(impl => ({
495-
file: impl.fileName,
496-
start: scriptInfo.positionToLineOffset(impl.textSpan.start),
497-
end: scriptInfo.positionToLineOffset(ts.textSpanEnd(impl.textSpan))
498-
}));
493+
return implementations.map(({ fileName, textSpan }) => {
494+
const scriptInfo = project.getScriptInfo(fileName);
495+
return {
496+
file: fileName,
497+
start: scriptInfo.positionToLineOffset(textSpan.start),
498+
end: scriptInfo.positionToLineOffset(ts.textSpanEnd(textSpan))
499+
};
500+
});
499501
}
500502
else {
501503
return implementations;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='../fourslash.ts'/>
2+
3+
// @Filename: /bar.ts
4+
////import {Foo} from './foo'
5+
////
6+
////[|class A implements Foo {
7+
//// func() {}
8+
////}|]
9+
////
10+
////[|class B implements Foo {
11+
//// func() {}
12+
////}|]
13+
14+
// @Filename: /foo.ts
15+
////export interface /**/Foo {
16+
//// func();
17+
////}
18+
19+
verify.allRangesAppearInImplementationList("");

0 commit comments

Comments
 (0)