Quramy / tsuquyomi

A Vim plugin for TypeScript
http://www.vim.org/scripts/script.php?script_id=5151
1.39k stars 72 forks source link

Issue with go to definition for is tsserver returns two results #234

Closed verkholantsev closed 6 years ago

verkholantsev commented 6 years ago

Hi! Thank you for such an amazing plugin. It makes TypeScript development in vim so much productive.

Looks like I've found and issue, please take a look at details.

Setup

Two files in project: a.ts and b.ts.

// a.ts

const a = () => { console.log('a'); }

export default a;

// b.ts

import a from './a';

a();

Steps to reproduce

  1. Put cursor on a() in b.ts
  2. Press C-] (or type :TsuDefinition)

Expected behaviour

Vim will open a.ts on const a = () => { ... } line

Actual behaviour

Vim does nothing

Reason

If we add debug output to tsuquyomi#gotoDefinition (source) we will see this response from tsserver:

[
    {
        file: '/Users/averkholantcev/tmp/tsuquyomi-issue/a.ts',
        end: { offset: 38, line: 1 },
        start: { offset: 11, line: 1 },
    },
    {
        file: '/Users/averkholantcev/tmp/tsuquyomi-issue/a.ts',
        end: { offset: 8, line: 1 },
        start: { offset: 7, line: 1 },
    },
];

In current implementation tsuquyomi#gotoDefinition will do nothing if length of results is not equal 1.

Do you think that it would be reasonable to change behaviour to take last element from the list if length is greater than 1?

verkholantsev commented 6 years ago

Closed issue because PR was merged