Skip to content

Allow language extensions to override editor.wordSeparators #33701

Closed

Description

@daviwil
  • 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!

Activity

  1. added
    editor-core
    on Sep 1, 2017
  2. added
    feature-request
    on Nov 27, 2017
  3. jrrdnx commented on Feb 21, 2018

    @jrrdnx

    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")
  4. rjmholt commented on Jun 17, 2018

    @rjmholt

    Following up on David Wilson (@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)?

  5. shanesmithdev commented on Jun 18, 2018

    @shanesmithdev

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

  6. rjmholt commented on Jun 19, 2018

    @rjmholt

    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.

  7. HookyQR commented on Feb 15, 2019

    @HookyQR
    Contributor

    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)

  8. TylerLeonhardt commented on Mar 5, 2019

    @TylerLeonhardt
    Member

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

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

    I think this means we can close this issue? 😊

  9. HookyQR commented on Mar 5, 2019

    @HookyQR
    Contributor

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

  10. TylerLeonhardt commented on Mar 5, 2019

    @TylerLeonhardt
    Member

    Hooky (@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 \$?.

  11. HookyQR commented on Mar 18, 2019

    @HookyQR
    Contributor

    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. 🤷‍♂️

  12. inspiredearth commented on Apr 21, 2020

    @inspiredearth

    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.

  13. inspiredearth commented on Apr 21, 2020

    @inspiredearth

    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": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?",
            }
    
  14. TylerLeonhardt commented on Apr 21, 2020

    @TylerLeonhardt
    Member

    Yeah I think this issue can be closed.

  15. locked and limited conversation to collaborators on Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    editor-corefeature-request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions