Can VS code be configured to accept punctuation?

This question especially addresses other C # developers who are switching to TypeScript in VS code.

I fell in love with code completion in VS C #. To illustrate, let's say I'm trying to write:

console.log('hello')

Using C #, I would:

  • type "con"
  • a list of suggestions appears, possibly starting with "console"
  • since it is highlighted, and this is what I want by clicking ".". write out the "sole". so now i have:console.
  • type "l", "log" - first sentence
  • type "(", now I have: console.log('')
  • the cursor is now in '
  • enter hi

Currently with my VS code setup, the same thing can be achieved in JS / TS, striking tabevery time I want to accept an offer. But just clicking on the next punctuation to continue was really nice, and if you forgive me for taking care of it, it’s “fun.” I miss him. And there are no technical restrictions in languages ​​that I know would prohibit this behavior.

Does anyone know if there are any extensions or settings to enable this? Or where else can this conversation take place?

+4
source share
2 answers

You can implement this using the macro extension . For this:

  • Install Macro Extension

  • , acceptSelectedSuggestion, .. Settings.json:

    {
        "editor.wordWrap": "on",
        "window.zoomLevel": 0,
        "git.enableSmartCommit": true,
        "macros": {
            "accept.": [
                "acceptSelectedSuggestion",
                {"command": "type", "args": {"text": "."}}
            ],
            "accept(": [
                "acceptSelectedSuggestion",
                {"command": "type", "args": {"text": "("}}
            ],        
            "accept=": [
                "acceptSelectedSuggestion",
                {"command": "type", "args": {"text": "="}}
            ]
        }
    }
    
  • keybindings.json. :

    {
        "key": ".",
        "command": "macros.accept.",
        "when": "editorTextFocus && suggestWidgetVisible"
    },
    {
        "key": "shift+9",
        "command": "macros.accept(",
        "when": "editorTextFocus && suggestWidgetVisible"
    },
    {
        "key": "=",
        "command": "macros.accept=",
        "when": "editorTextFocus && suggestWidgetVisible"
    }
    

    VS # 3 . , , , .

+1

, . console, :

→ > .

keybindings.json. :

{ "key": ".",                   "command": "acceptSelectedSuggestion",
                                 "when": "editorTextFocus && suggestWidgetVisible" },

.

0

Source: https://habr.com/ru/post/1686492/


All Articles