Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path-intellisense.mappings doesn't work / not used correctly #51

Open
lironess opened this issue Jan 9, 2017 · 33 comments
Open

path-intellisense.mappings doesn't work / not used correctly #51

lironess opened this issue Jan 9, 2017 · 33 comments

Comments

@lironess
Copy link

lironess commented Jan 9, 2017

i tried using that to solve my webpack absolute pathto autocomplete modules.

  • The projects sits on /Users/myuser/Workspace/foo.
  • The directory that I want to autocomplete is /Users/myuser/Workspace/foo/src.
  • I want to use it on my code so I can write in a file:
import Bar from 'utils/bar'

and it will be resolved to: /Users/myuser/Workspace/foo/src/utils/bar.

I tried as above:

"path-intellisense.mappings": {
    "/": "${workspaceRoot}/src"
}

what am i doing wrong ?

also - my src folder contains 10 directories that I want to be auto-mapped.. do I have to add a record for each of them or it will be auto-mapped ?

@ChristianKohler
Copy link
Owner

Try to add a slash before the path:

import Bar from '/utils/bar'

Does this work?

@lironess
Copy link
Author

nope :(

@lironess
Copy link
Author

no way to make it without / and just to import resolve from webpack config ?

@ekorzun
Copy link

ekorzun commented Jan 27, 2017

Got the same issue.

Here is my config:

"path-intellisense.mappings": {
    "/": "${workspaceRoot}/main/src",
    "controllers": "${workspaceRoot}/main/src/controllers",
    "components": "${workspaceRoot}/main/src/components"
}

When I use it with elements' attrs it works
monosnap 2017-01-27 20-51-06

image

It also works with exports
image

But the only thing I need to be work – doesn't work :)
image

@lekhnath
Copy link

lekhnath commented Feb 3, 2017

I've the following settings:

"path-intellisense.mappings": {
      "src": "${workspaceRoot}/src",
      "server": "${workspaceRoot}/server"
  }

and having the same issue as @korzhik mentioned.

But this feature was working fine for me in its previous version 1.1.0, auto suggest while importing and/or requireing suddendly break after upgrading to its latest v1.2.0.

@ChristianKohler
Copy link
Owner

i tried to reproduce the error. I set the same setting as @korzhik and set up the same folder structure. It works on my mac. Could you help me to reproduce the problem? Best would be a small project which I could clone. Thank you.

"components": "${workspaceRoot}/main/src/components"

screen shot 2017-02-06 at 21 31 32

@mike623
Copy link

mike623 commented Feb 20, 2017

@ChristianKohler as you said. It is work. But is not similar behaviour as how alias in webpack work.
for example.

I expect
"*": "${workspaceRoot}/main/src" instead of
"components": "${workspaceRoot}/main/src/components"

Then I can type whatever import x from components or import y from containers.
In your case. Should I need to keep maintain project structure?

@lironess
Copy link
Author

lironess commented Feb 27, 2017

@ChristianKohler even your example doesn't work for me...
here are my extensions:

CoenraadS.bracket-pair-colorizer
christian-kohler.npm-intellisense
christian-kohler.path-intellisense
dbaeumer.vscode-eslint
donjayamanne.githistory
felipecaputo.git-project-manager
formulahendry.auto-close-tag
robertohuertasm.vscode-icons
samverschueren.final-newline
zhuangtongfa.Material-theme

and this is my config:

// Place your settings in this file to overwrite the default settings
{
    "gitProjectManager.baseProjectsFolders": [ "/Users/lironshmuel/Workspace" ]
,
"files.insertFinalNewline": true,
"npm-intellisense.packageSubfoldersIntellisense": true,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": true,
"editor.fontSize": 13,
"editor.tabSize": 2,
"window.zoomLevel": 0,
"vsicons.projectDetection.autoReload": true,
"path-intellisense.mappings": {
    "/": "${workspaceRoot}/src"
}
}

trying to import a file from src directory (which located on root of the project) without success (trying to import from /myfile.js which is on my project root directory/src/myfile.js

@kib357
Copy link

kib357 commented Mar 2, 2017

@ChristianKohler i figured out that you can reproduce this issue by installing both path-intellisense and npm-intellisense.

@lironess
Copy link
Author

lironess commented Mar 2, 2017

I'm also having both packages, so this might be the problem .. (although you wrote them both 😆 )

@AvailCat
Copy link

AvailCat commented Mar 3, 2017

mappings not work if npm-intellisense installed

@DollarAkshay
Copy link

having this issue without npm-intellisense installed

@rake5k
Copy link

rake5k commented May 8, 2017

Same problem here on Mac OS X Sierra. My settings.json:

{
    "path-intellisense.mappings": {
        ".": [
            "${workspaceRoot}/api/app",
            "${workspaceRoot}/web/app"
        ]
    }
}

The exact same mappings work like a charm on my Ubuntu 16.04 machine.

Side note: I even was excited that multiple paths are working by defining them in an array 👍

@iddan
Copy link

iddan commented May 9, 2017

same here: trying to map my app/ directory to be used without prefix in my code:

{
    "path-intellisense.mappings": {
         "/": "${workspaceRoot}/app"
     }
}

both import '/' and import '' don't provide suggestions

@kuldeepkeshwar
Copy link

have anyone got any success on this ?

@Player1os
Copy link

had the same problem, the issue seems to be that as soon as you write anything other than '.', '..', '...', etc. as the prefix of the import path, npm-intellisense kicks in and overrides path-intellisense

so a quickfix for me was to to use this

"path-intellisense.mappings": {
	"...": "${workspaceRoot}"
},

that way import '.../src/index' triggers path-intellisense and npm-intellisense works fine on npm modules as well

PS: I used to use '#' as the mapping but I actually like '...' better now that I think about it ... it's closer to the '.' and '..' originally used to denote project specific modules in vanilla node.js require statements

@vanhtuan0409
Copy link

vanhtuan0409 commented Jun 23, 2017

I think the problem comes from npm-IntelliSense

@Mr-Chilly
Copy link

Is there any joy with this? I found the {...} solution from @Player1os was the only thing to work - but that isn't actually useful for my needs...

@lucasbento
Copy link

@vanhtuan0409: that's not how OSS works, it's much better to send a PR than order maintainers to fix it.

@vanhtuan0409
Copy link

@lucasbento I am sorry. I don't mean to order anyone to do anything. My words are inappropriate.

@wesleymostien
Copy link

absolute mapping is not working either for me. Don't have npm intellisense extension...

@srg-kostyrko
Copy link

It seems that vscode's import path quick suggestions break mappings
After I added

"typescript.quickSuggestionsForPaths": false,

and with

"path-intellisense.mappings": {
     "@": "${workspaceRoot}/app"
 }

it started to provide correct suggestions for import from '@/'

@MadratJerry
Copy link

Disable npm intellisense extension and add

"typescript.quickSuggestionsForPaths": false,

it works for me now

@Ayc0
Copy link

Ayc0 commented Jul 6, 2018

does it still work with the last update ?

@hyposlasher
Copy link

it doesn't work with the last update. I didn't find "typescript.quickSuggestionsForPaths": false, anywhere in "settings"

@george-norris-salesforce

I've uninstalled npm-intellisense and getting same error

@rardoz
Copy link

rardoz commented Aug 15, 2019

Removed npm-intellisense and there is no such thing as typescript.quickSuggestionsForPaths. Still getting the same issue.

@liesauer
Copy link

same issue and npm-intellisense isn't installed and there is no such thing as typescript.quickSuggestionsForPaths.
image
image
image

@lsalomon
Copy link

lsalomon commented Apr 2, 2020

same here, vscode 1.43.2 on OSX 10.15.4, don't have npm intellisense, and yet any of the following configs is working :

    "path-intellisense.absolutePathToWorkspace": false,
    "path-intellisense.mappings": {
        "/": "/Users/laurent.salomon/Workspace/my-app/public"
    },
    "path-intellisense.absolutePathToWorkspace": true,
    "path-intellisense.mappings": {
        "/": "/Users/laurent.salomon/Workspace/my-app/public"
    },
    "path-intellisense.absolutePathToWorkspace": false,
    "path-intellisense.mappings": {
        "/": "${workspaceRoot}/public"
    },
    "path-intellisense.absolutePathToWorkspace": true,
    "path-intellisense.mappings": {
        "/": "${workspaceRoot}/public"
    },
    "path-intellisense.absolutePathToWorkspace": true,
    "path-intellisense.mappings": {
        "/": "public"
    },

@kenmarshall
Copy link

I got mine to work by disabling a few default path suggestions

    "typescript.suggest.paths": false,
    "javascript.suggest.paths": false,
    "path-intellisense.mappings": {
       "/": "${workspaceFolder}",
      "components" :  "${workspaceFolder}/client/src/components"
    },

Depending on which language you are working in you may have to disable the default setting {language}.suggest.paths
You can make the settings specific only to a workspace which makes it more convenient.

I didn't need to disable any other extension.

jheiv added a commit to jheiv/PathIntellisense that referenced this issue Jan 4, 2022
- Fixes (ChristianKohler#48, ChristianKohler#157)
- Potentially fixes (ChristianKohler#51)
- Adds 'absolutePathTo' setting, a more flexible absolutePathToWorkspace
- Adds 'showOnAbsoluteSlash' setting, allowing you to see suggestions on initial slash
- Adds a number of testcases for the new behavior (and fortifies an existing one that was causing me a ton of headache)
- Tiny tweak to test/suite/index.ts to get rid of a deprecation warning re: color
ChristianKohler pushed a commit that referenced this issue Jan 14, 2022
…193)

- Fixes (#48, #157)
- Potentially fixes (#51)
- Adds 'absolutePathTo' setting, a more flexible absolutePathToWorkspace
- Adds 'showOnAbsoluteSlash' setting, allowing you to see suggestions on initial slash
- Adds a number of testcases for the new behavior (and fortifies an existing one that was causing me a ton of headache)
- Tiny tweak to test/suite/index.ts to get rid of a deprecation warning re: color
github-actions bot pushed a commit that referenced this issue Jan 14, 2022
## [2.6.1](v2.6.0...v2.6.1) (2022-01-14)

### Bug Fixes

* Improve absolute path handling (mostly-Windows fixes, some QOL) ([#193](#193)) ([c9d7471](c9d7471)), closes [#48](#48) [#157](#157) [#51](#51)
@zepvalue
Copy link

zepvalue commented Jan 18, 2022

It may also be that is throttling a bit so maybe would help to disable the intellisense on certain paths in the settings.json

( especially node_modules!)

"files.watcherExclude": { "**/.git/objects/**": true, "**/.git/subtree-cache/**": true, "**/node_modules/*/**": true, "**/tmp/**": true, "**/dist/**": true, "**/public/**": true }

@ChristianKohler
Copy link
Owner

Thank you @zepvalue

Did you notice or measure that PathIntellisense has an issue with file watchers? Asking because mappings are not watched. But the extension has a single file watcher to check for changes in tsconfig files. But never heard of any problems with that one. 🤔

@zepvalue
Copy link

The only change I noticed was in the speed that PathIntellisense was indexing files. In react components with absolute path would take a bit before I forced the watchers options. I am not sure how the tsconfig works under the hood together with vscode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests