Skip to content

Change to references' lineText property breaks find-all-references in emacs #25489

Closed
@sandersn

Description

@sandersn
var g = function (x) {
  console.log(x)
  return x/**/
}

Find all references at x (any of them) in emacs.

Expected behavior:
Three lines:

test.js
  6:var g = function (x) {
  7:  console.log(x)
  8:  return x

Actual behavior:
Crash with emacs' inscrutable equivalent of index out of bounds ("let: Args out of range: 18, 19"). Deleting the body of tide-annotate-line stops the crash and exposes the real problem:

test.js
  6:x
  7:x
  8:x

lineText was previously the entire line text and is now just the text of the identifier. I am pretty sure that #25283 caused this change. I think it is unintentional and incorrect based on the description in protocol.ts:

        /** Text of line containing the reference.  Including this
         *  with the response avoids latency of editor loading files
         * to show text of reference line (the server already has
         * loaded the referencing files).
         */
        lineText: string;

Actually setting up emacs + tide + custom tsserver + custom logger is cumbersome and probably not necessary. Here is the before/after json object for this request:

2.9.2

{"seq":0,"type":"response","command":"references","request_seq":"200","success":true,"body":{"refs":[
    {"file":"/home/n/src/test/test.js","start":{"line":6,"offset":19},"lineText":"var g = function (x) {","end":{"line":6,"offset":20},"isWriteAccess":true,"isDefinition":true},
    {"file":"/home/n/src/test/test.js","start":{"line":7,"offset":17},"lineText":"    console.log(x);","end":{"line":7,"offset":18},"isWriteAccess":false,"isDefinition":false},
    {"file":"/home/n/src/test/test.js","start":{"line":8,"offset":12},"lineText":"    return x }","end":{"line":8,"offset":13},"isWriteAccess":false,"isDefinition":false}],"symbolName":"x","symbolStartOffset":12,"symbolDisplayString":"(parameter) x: HTMLElement"}}

3.0

{"seq":0,"type":"response","command":"references","request_seq":"203","success":true,"body":{"refs":[
    {"file":"/home/n/src/test/test.js","start":{"line":6,"offset":19},"end":{"line":6,"offset":20},"lineText":"x","isWriteAccess":true,"isDefinition":true},
    {"file":"/home/n/src/test/test.js","start":{"line":7,"offset":17},"end":{"line":7,"offset":18},"lineText":"x","isWriteAccess":false,"isDefinition":false},
    {"file":"/home/n/src/test/test.js","start":{"line":8,"offset":12},"end":{"line":8,"offset":13},"lineText":"x","isWriteAccess":false,"isDefinition":false}],"symbolName":"x","symbolStartOffset":12,"symbolDisplayString":"(parameter) x: HTMLElement"}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions