PathIntellisense icon indicating copy to clipboard operation
PathIntellisense copied to clipboard

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

Open lironess opened this issue 8 years ago • 33 comments

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 ?

lironess avatar Jan 09 '17 23:01 lironess

Try to add a slash before the path:

import Bar from '/utils/bar'

Does this work?

ChristianKohler avatar Jan 10 '17 20:01 ChristianKohler

nope :(

lironess avatar Jan 11 '17 19:01 lironess

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

lironess avatar Jan 14 '17 22:01 lironess

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

ekorzun avatar Jan 27 '17 12:01 ekorzun

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.

lekhnath avatar Feb 03 '17 14:02 lekhnath

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

ChristianKohler avatar Feb 06 '17 20:02 ChristianKohler

@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?

mike623 avatar Feb 20 '17 07:02 mike623

@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

lironess avatar Feb 27 '17 13:02 lironess

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

kib357 avatar Mar 02 '17 14:03 kib357

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

lironess avatar Mar 02 '17 20:03 lironess

mappings not work if npm-intellisense installed

AvailCat avatar Mar 03 '17 07:03 AvailCat

having this issue without npm-intellisense installed

DollarAkshay avatar Mar 25 '17 16:03 DollarAkshay

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 👍

rake5k avatar May 08 '17 08:05 rake5k

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

iddan avatar May 09 '17 11:05 iddan

have anyone got any success on this ?

kuldeepkeshwar avatar Jun 06 '17 05:06 kuldeepkeshwar

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

Player1os avatar Jun 17 '17 08:06 Player1os

I think the problem comes from npm-IntelliSense

vanhtuan0409 avatar Jun 23 '17 09:06 vanhtuan0409

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...

Mr-Chilly avatar Aug 14 '17 09:08 Mr-Chilly

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

lucasbento avatar Oct 10 '17 09:10 lucasbento

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

vanhtuan0409 avatar Oct 11 '17 06:10 vanhtuan0409

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

wesleymostien avatar Oct 13 '17 15:10 wesleymostien

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 '@/'

srg-kostyrko avatar Jan 22 '18 12:01 srg-kostyrko

Disable npm intellisense extension and add

"typescript.quickSuggestionsForPaths": false,

it works for me now

MadratJerry avatar Jan 29 '18 07:01 MadratJerry

does it still work with the last update ?

Ayc0 avatar Jul 06 '18 16:07 Ayc0

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

hyposlasher avatar Sep 25 '18 11:09 hyposlasher

I've uninstalled npm-intellisense and getting same error

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

rardoz avatar Aug 15 '19 15:08 rardoz

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

liesauer avatar Dec 18 '19 14:12 liesauer

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"
    },

lsalomon avatar Apr 02 '20 13:04 lsalomon

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.

kenmarshall avatar Apr 11 '21 11:04 kenmarshall