In which context will PhpStorm offer path autocomplete in JavaScript files.

Hi,

I'm working on a project with a lot of assets files and I'm trying to find a way to handle entering file path easily.

I know PhpStorm offers autocomplete for path in specific context (e.g. css url('/path'), js import from "./path", ...)

I also discovered that sometimes, autocomplete will kick in based on some criteria:

const BASE_PATH = "../assets/"

function path1(url){
return url
}

function path2(path){
return path
}

function path3(resource){
return resource
}

export const GameAssets = {
test1: BASE_PATH + 'phaser3-logo.png',
test2: path1('../assets/phaser3-logo.png'),
test3: path2('../assets/phaser3-logo.png'),
test4: path3('../assets/phaser3-logo.png'),
test5: path1('')
}

In the code above, I never have autocomplete except when using path1 where the parameter is named 'url' and it tries to autocomplete with an url and also underline the url in the function call

So now I'm wondering if there's a specific parameter name or context I could setup to trick PhpStorm to offer path autocomplete for my asset folder (or maybe some live template expression combination).

Methods that work but are not ideal:
- Using file completion in imports when using webpack :

import fileKey from '../assets/phaser3-logo.png'

- Using Language injection > File reference in every single string I would like to be a path.

Bonus question: regarding the "url" parameter above, is there other special name that change the behaviour of the editor and is this configurable somewhere ? 

0
1 comment

You can create custom injections like

// language=file-reference
path2('../assets/phaser3-logo.png')

An injection that would work without a comment can't be created because of this known issue: https://youtrack.jetbrains.com/issue/WEB-35166.

1

Please sign in to leave a comment.