microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.3k stars 12.53k forks source link

TypeScript LSP: Renaming `toString(data)` method renames also `toString()` method on an unrelated class #54356

Closed hpopov closed 3 months ago

hpopov commented 1 year ago

Type: Bug

  1. Given that I have an NPM project with 'uuid' dependency installed, and some custom class A with toString method in it. This method is not used. See my project file, where I encountered the issue.
  2. Using Fn+F2 keyboard combination, I rename the toString method on my custom class A Rename toString method

Expected result: only A.toString method changes its name.

Actual result: library method URI.toString also changes its name 😲(though it is not related to class A in the inheritance hierarchy). Unrelated function from NPM library gets renamed.

See this commit diff on my project. You can also follow last 2 commits on the branch external-bug/ts-server-renaming-to-string-from-the-npm-libraries to see performed steps from above in the commit diffs.

VS Code version: Code 1.78.2 (b3e4e68a0bc097f0ae7907b217c1119af9e03435, 2023-05-10T14:39:26.248Z) OS version: Windows_NT x64 10.0.22621 Modes: Sandboxed: No Remote OS version: Linux x64 5.10.16.3-microsoft-standard-WSL2

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz (12 x 2592)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|31.77GB (11.48GB free)| |Process Argv|--crash-reporter-id 4cc4ddd6-f235-4b0a-b774-744ef6baac4d| |Screen Reader|no| |VM|0%| |Item|Value| |---|---| |Remote|Dev Container: Node.js & TypeScript| |OS|Linux x64 5.10.16.3-microsoft-standard-WSL2| |CPUs|Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz (12 x 2592)| |Memory (System)|15.52GB (13.96GB free)| |VM|0%|
Extensions (47) Extension|Author (truncated)|Version ---|---|--- ng-template|Ang|16.0.0 insert-unicode|bru|0.14.0 vscode-markdownlint|Dav|0.50.0 vscode-eslint|dba|2.4.0 FreeMarker|dco|0.0.9 maven-dependency-explorer|dhr|1.0.17 gitlens|eam|13.6.0 EditorConfig|Edi|0.16.4 prettier-vscode|esb|9.12.0 git-project-manager|fel|1.8.2 codetogether|gen|2023.1.1 gitpod-desktop|git|0.0.110 xtend-lang|Gra|0.3.0 xtext-lang|gra|0.4.0 todo-tree|Gru|0.0.226 jbockle-format-files|jbo|3.4.0 svg|joc|1.5.2 langium-vscode|lan|1.2.0 git-graph|mhu|1.30.0 vscode-docker|ms-|1.25.1 remote-containers|ms-|0.292.0 remote-ssh|ms-|0.102.0 remote-ssh-edit|ms-|0.86.0 cmake-tools|ms-|1.14.31 cpptools|ms-|1.15.4 cpptools-extension-pack|ms-|1.3.0 remote-explorer|ms-|0.4.0 fabric8-analytics|red|0.3.10 java|red|1.18.0 vscode-xml|red|0.25.0 vscode-gitweblinks|red|2.9.2 vscode-checkstyle|she|1.4.2 default-keys-windows|smc|0.0.9 cmake|twx|0.0.17 intellicode-api-usage-examples|Vis|0.2.7 vscodeintellicode|Vis|1.2.30 vscode-boot-dev-pack|vmw|0.2.1 vscode-spring-boot|vmw|1.46.0 vscode-gradle|vsc|3.12.7 vscode-java-debug|vsc|0.50.0 vscode-java-dependency|vsc|0.22.0 vscode-java-pack|vsc|0.25.11 vscode-java-test|vsc|0.38.2 vscode-maven|vsc|0.41.0 vscode-spring-boot-dashboard|vsc|0.13.0 vscode-spring-initializr|vsc|0.11.2 vitest-explorer|Zix|0.2.41 (1 theme extensions excluded)
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 pythondataviewer:30285071 vscod805cf:30301675 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 cmake_vspar411:30581797 vsaa593:30376534 pythonvs932:30410667 cppdebug:30492333 vsclangdc:30486549 c4g48928:30535728 dsvsc012cf:30540253 pynewext54:30695312 azure-dev_surveyone:30548225 282f8724:30602487 pyind779:30671433 f6dab269:30613381 pythonsymbol12:30671437 2i9eh265:30646982 showlangstatbar:30737416 vsccsb:30705552 azdwalk:30721579 pythonms35:30701012 03d35959:30706073 pythonfmttext:30731395 fixshowwlkth:30730052 hidesbindicator:30730055 pythongtdpath:30739704 ```
fatcerberus commented 1 year ago

This likely happens because URI#toString is related to A#toString through Object.prototype, so it's like renaming any other overridden method in how it affects sibling classes.

hpopov commented 1 year ago

Anyway, it doesn't seem right to me, that library classes are affected. This is not expected, is it?

RyanCavanaugh commented 1 year ago

This seems weird and I can't reproduce this behavior in another context. Can you produce an isolated example?