microsoft / TypeScript

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

Wrong module-path shown on IntelliSense #57723

Closed hahoyer closed 8 months ago

hahoyer commented 8 months ago

Type: Bug

For reasons, I have remapped a directory on my computer:

subst a: c:\Data\A

For example, I start vscode with the path "A:\develop\Hello", which is the directory where my Javascript application is located. The require statements where the path starts with "./" are displayed correctly, e.g.

require "./myModule" 

shows when hovering:

module "A:\develop\Hello\myModule" 

If the require statement is like the following:

require "myModule"

is shows:

module "c:\Data\A\develop\Hello\myModule" 

instead.

How can I prevent this? The module path should of course always be within the project directory. Like in the first version. (The first version can only be used as an alternative at the top level.) When I execute require.resolve I get the correct paths. With code.insiders (Version: 1.88.0-insider) it shows the same behavior.

VS Code version: Code 1.87.1 (1e790d77f81672c49be070e04474901747115651, 2024-03-06T00:21:36.258Z) OS version: Windows_NT x64 10.0.19045 Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i9-10900KF CPU @ 3.70GHz (20 x 3696)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
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
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|31.87GB (7.07GB free)| |Process Argv|A:\\develop\\tutory\\webapp.other --crash-reporter-id ef3f0a5c-2447-4344-ae93-8f34f0b999ca| |Screen Reader|no| |VM|0%|
Extensions (25) Extension|Author (truncated)|Version ---|---|--- ng-template|Ang|17.2.2 dbclient-jdbc|cwe|1.3.4 vscode-database-client2|cwe|7.0.9 vscode-markdownlint|Dav|0.54.0 vscode-eslint|dba|2.4.4 prettier-vscode|esb|10.1.0 vscode-test-explorer|hbe|2.21.1 factoriomod-debug|jus|1.1.41 tgit-cmds|mbi|1.4.2 import-sorter|mik|3.3.1 csdevkit|ms-|1.3.10 csharp|ms-|2.18.16 vscode-dotnet-runtime|ms-|2.0.2 vscodeintellicode-csharp|ms-|0.1.26 cmake-tools|ms-|1.17.17 cpptools|ms-|1.19.6 cpptools-extension-pack|ms-|1.3.0 test-adapter-converter|ms-|0.1.9 prettyxml|Pra|4.4.1 markdown-preview-enhanced|shd|0.8.12 vscode-zipexplorer|sle|0.3.1 lua|sum|3.7.4 factorio-lua-api-autocomplete|svi|0.7.0 cmake|twx|0.0.17 markdown-all-in-one|yzh|3.6.2 (1 theme extensions excluded)
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscorecescf:30445987 vscod805cf:30301675 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:30899288 vscaat:30438848 c4g48928:30535728 azure-dev_surveyone:30548225 962ge761:30959799 9b8hh234:30694863 pythongtdpath:30769146 welcomedialogc:30910334 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 pythontbext0:30879054 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:30979542 d34g3935:30971562 fegfb526:30981948 bg6jg535:30979843 dsvsc020:30976470 666c4381:30973075 ```
mjbvz commented 8 months ago

What language is this for?

hahoyer commented 8 months ago

Node.js v20.9.0

fatcerberus commented 8 months ago

Note that TS will never rewrite your import paths so this is ultimately just a display issue.

hahoyer commented 8 months ago

Not only. When I klick the path it opens the module file with the wrong path. That is actually the main problem. Sorry, forgot to mention that.

fatcerberus commented 8 months ago

I guess I don't understand why that's a problem--since you're using subst ultimately both paths refer to the same file. Is there something else in the editing experience that's broken by opening the file from the wrong path?

hahoyer commented 8 months ago

I guess I don't understand why that's a problem

Really?

RyanCavanaugh commented 8 months ago

Not really enough information for me to repro this, but you can toggle the preserveSymlinks setting depending on whether you want real-paths or symlink-paths

hahoyer commented 8 months ago

Not really enough information for me to repro this

Suppose the current directory is your user area ("C:\Users\<username>"). Create direcory named (for example) "linkTest". Select a drive name that is not used jet for example "t:". Create a Windows mapping by use of subst-command:

    subst t: .\linkTest

Create a directory - for example "t:\sample" Open this with vscode.

Create a file ./app.js like this:

    require("modules/myModule")

Create an empty file ./modules/myModule.js

By use of symlink-dir map ./modules into ./node_modules To do this do

npm add symlinks-dir

Create a file symlinks.js like this:

    'use strict'
    const symlinkDir = require('symlink-dir')
    symlinkDir('modules', 'node_modules/modules')

and run with node:

    #  node
    >  require('./symlinks')

To see that this actually working you can try this:

    # node
    > require.resolve("modules/myModule")

You will get 'T:\sample\modules\myModule.js' as result

Now open app.js and control-klick on "modules/myModule". The path will be "C:\Users\<username>\linkTest\sample\modules\myModule.js". It should be "T:\sample\modules\myModule.js".

fatcerberus commented 8 months ago

Did you try the preserveSymlinks option Ryan mentioned? https://www.typescriptlang.org/tsconfig#preserveSymlinks

hahoyer commented 8 months ago

I don't understand where to use this option. Can you help?

fatcerberus commented 8 months ago

You have to put it in your tsconfig.json... or jsconfig.json if this is a vanilla JS project. https://code.visualstudio.com/docs/languages/jsconfig

{
    "compilerOptions": {
        "preserveSymlinks": true
    }
}
hahoyer commented 8 months ago

When I do this it goes to T:\sample\node_modules\modules\myModule.js - as expected. Also wrong.

hahoyer commented 8 months ago

I'm just wondering why this issue ended up in the TypeScript repo. I opened it from within vscode (help/report issue) and expected it to be created in the vscode repo as well. Isn't it wrong here?

fatcerberus commented 8 months ago

It was moved because intellisense in the IDE for JS code is handled by the typescript language service.

hahoyer commented 8 months ago

I also wonder where the information about the actual path actually comes from. As far as I know, you can only get it via kernel functions such as QueryDosDevice. But QueryDosDevice does not appear in the typescript repo. How does that work?

typescript-bot commented 8 months ago

This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes.