Skip to content

Go to definition hover preview should not open a document on TS Server #84875

Closed

Description

@mjbvz

Issue Type: Bug

Repo

  1. Enable ts server logging: "typescript.tsserver.log": "verbose"
  2. With a workspace:

index.ts

import { a } from "./a";

console.log(a);

a.ts

export const a = 1;
  1. Close all files and restart VS Code
  2. Open index.ts
  3. Hover over a in console.log(a) and trigger preview

Bug
This causes a.ts to be opened by the JS/TS extension (through onDidOpenTextDocument)

To confirm this, look through the ts server logs

/cc Andrew Casey (@amcasey)

VS Code version: Code - Insiders 1.41.0-insider (eccf417, 2019-11-14T09:48:11.894Z)
OS version: Darwin x64 18.7.0

System Info
Item Value
CPUs Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz (8 x 2200)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off
surface_control: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 2, 2, 2
Memory (System) 16.00GB (0.14GB free)
Process Argv -psn_0_2519655
Screen Reader no
VM 0%

Activity

  1. mjbvz commented on Nov 14, 2019

    @mjbvz
    ContributorAuthor

    Place in code where this is triggered:

    this.textModelResolverService.createModelReference(result.uri).then(ref => {

  2. changed the title [-]Go to definition hover preview should not open an text document that is visible to extensions[/-] [+]Go to definition hover preview should not open a text document that is visible to extensions[/+] on Nov 14, 2019
  3. jrieken commented on Nov 15, 2019

    @jrieken
    Contributor

    There is only that one way to load a document, esp when being in the editor layer, this won't change. I don't understand why typescript reacts to this "in a bad way" but I guess what you want is something is knowledge about open editors/tabs, e.g this #15178.

  4. added
    *as-designed
    on Nov 15, 2019
  5. vscodebot commented on Nov 15, 2019

    @vscodebot

    The described behavior is how it is expected to work. If you disagree, please explain what is expected and what is not in more detail. See also our issue reporting guidelines.

    Happy Coding!

  6. jrieken commented on Nov 15, 2019

    @jrieken
    Contributor

    Closing as designed since there is no alternative and since text documents can be opened via various different paths (e.g by another extensions). Band aiding won't help the root issue which I believe is the lack of reflecting open editors or maybe TS being less aggressive in starting "an expensive project load"

  7. mjbvz commented on Nov 15, 2019

    @mjbvz
    ContributorAuthor

    This was a pain point that TS specifically brought up so we should prioritize addressing it (like they do for our issues). TypeScript is seeing users report unexpected project loads reported, and it seems these are most often triggered by hover (although you are correct that extensions can also trigger this by opening text documents)

    #15178 would let us fix the issue. However are there any other workarounds we can try before #15178 is addressed? I'm tempted to try checking the file against visibleTextEditors but have a feeling that may not work

  8. jrieken commented on Nov 15, 2019

    @jrieken
    Contributor

    This was a pain point that TS specifically brought up so we should prioritize addressing it (like they do for our issues).

    I am all for that, I just don't wanna do a hack which then only works half of the time.

    I'm tempted to try checking the file against visibleTextEditors but have a feeling that may not work

    That could work - it's by definition a subset of what open editors will be so you might miss things. You could try to wait a little when a document appears, esp one without an editor. In the hover case the model should be unref'ed/disposed very shortly after opening it. That could make things less aggressive

  9. amcasey commented on Nov 15, 2019

    @amcasey
    Member

    Could there be an intermediate state where VS Code regards the document as open but doesn't tell the TS server about it? That would be enough to prevent project load.

  10. removed
    *as-designed
    on Nov 15, 2019
  11. added
    javascript
    typescript
    on Nov 15, 2019
  12. mjbvz commented on Nov 15, 2019

    @mjbvz
    ContributorAuthor

    Reopening and making this JS/TS specific. Will look into the fix today

  13. changed the title [-]Go to definition hover preview should not open a text document that is visible to extensions[/-] [+]Go to definition hover preview should not open a document on TS Server[/+] on Nov 15, 2019
  14. mjbvz commented on Nov 15, 2019

    @mjbvz
    ContributorAuthor

    To verify this, use the listed repo steps. In the TS Server log, look for lines that show updateOpen requests:

        {"seq":2,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":[],"openFiles":[{"file":"/Users/matb/projects/san/index.ts","fileContent":"import { a } from \"./a\";\n\nconsole.log(a)\n","projectRootPath":"/Users/matb/projects/san","scriptKindName":"TS"}]}}
    

    Make sure that a.ts is never listed in one of these updateOpen requests on hover

  15. added
    bug
    on Nov 15, 2019
  16. added
    verified
    on Dec 5, 2019
  17. locked and limited conversation to collaborators on Dec 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugjavascripttypescriptverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions