Vscode: Allow language extensions to override editor.wordSeparators

Created on 1 Sep 2017  ·  14Comments  ·  Source: microsoft/vscode

  • VSCode Version: 1.15.1
  • OS Version: Any

There's a pretty common request from PowerShell extension users to enable double-click selection of variable names like $myVar including the initial dollar sign character. After some research it seems that the only way to control this double-click selection behavior is by having the user change their editor.wordSeparators setting to remove the $ which is included by default.

Is there any way that a language extension can override this setting (or behavior) for a specific language aside from editing the user's settings file to add this setting? If not, is it possible to programmatically add or edit a language-specific config section (like [powershell]) in the user's config?

Thanks!

editor-core feature-request

Most helpful comment

Add this to your settings to get this only for PowerShell!:

{
    "[powershell]": {
        "editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?"
    }
}

I _think_ this means we can close this issue? 😊

All 14 comments

I would like this as well. For me:

  • do _not_ select the "." in JS files (when selecting objects/properties using dot notation)
  • _do_ select the dot in CSS files (when selecting values such as "1.5rem")

Following up on @daviwil's question: Without looking for an implementation, is there any mechanism currently available to change the word separation characters for particular languages or extensions (i.e. as an extension developer)?

@tylerl0706 - that was mentioned in the original post that started this discussion.

The request is to extend that, so that it can be defined on a per-language (or per-filetype) basis, rather than globally.

Yes, and in our case I think an API for the extension to hook in or set this setting (or one related to it) is desired — some way to specify that word separators for our particular language do not include $. That kind of setting doesn't really make sense to me on a per-user basis — everyone using PowerShell (in our case) will generally want the same word definition and not need to set it themselves.

Just found this is problematic for code completion for 'words' which begin with $ as well. The code completion (24|7) is not triggered until the next character (eg. the f of $f) is typed, simple insertion (with the CompletionItem.label) results in double $$ as a result. The $ is not highlighted in the suggestions either.

Setting the wordSeparators (as the user) still doesn't trigger code completion until after the first non-$ character. I'm assuming this would be the case for any other character not present (removed) from the wordSeparators list, which IMO is contrary to the user's intent in that case.

Removing a character from that list should make it valid as a 'word' character. Thus, for the $ case, a$b should be added to the auto complete list (of words in the file) but it isn't.

Version 1.31.0-insider (2019-02-04)

Add this to your settings to get this only for PowerShell!:

{
    "[powershell]": {
        "editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?"
    }
}

I _think_ this means we can close this issue? 😊

Doesn't solve my problem of symbols beginning with characters considered to be wordSeparators by default.

@HookyQR I believe this might be a PowerShell extension issue. Can you test something for me?

Open this file:

~/.vscode-insiders/extensions/ms-vscode.powershell-1.11.0/out/src/main.js

and modify line 45 from:

        wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\'\"\,\.\<\>\/\?\s]+)/g,

to

        wordPattern: /(\$?-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\'\"\,\.\<\>\/\?\s]+)/g,

Note the additional \$?.

I'm saying, I'm creating a new extension, I don't use powershell, or the extension. The problem is in the VS Code mainline ... somewhere. 🤷‍♂️

Where did this issue get to?

Is it possible to define editor.wordSeparators on a per language basis? (as asked by the original poster?)

Currently, when editing PHP file, if I double click on variables, selectors, values, etc., with hyphens in them, I end up selecting on part of it. E.g., Double-clicking review in jgm-review-widget will only select review. I would expect it to select jgm-review-widget in its entirety.

Where did this issue get to?

Is it possible to define editor.wordSeparators on a per language basis? (as asked by the original poster?)

I seem to have answered my own question. Applying the following User Setting, I was able to modify editor.wordSeparators for just PHP:

 "[php]": {
            "editor.wordSeparators": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?",
        }

Yeah I think this issue can be closed.

Was this page helpful?
0 / 5 - 0 ratings