Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto indent when press ENTER after colon #279

Open
eailfly opened this issue Feb 26, 2020 · 12 comments
Open

Auto indent when press ENTER after colon #279

eailfly opened this issue Feb 26, 2020 · 12 comments

Comments

@eailfly
Copy link

eailfly commented Feb 26, 2020

I'm trying figure out how to make vscode indent after I press ENTER after colon, like this

name:
  echo: "It should place cursor under letter 'm' automatically"

It should have indented and placed the cursor under the letter 'm' (2 spaces) when I pressed the enter key after "name:"

But I can't seem to get it to work. It just puts the cursor underneath the letter 'n'.

@JPinkney
Copy link
Contributor

I'm not entirely sure if we have the ability to customize what happens when you just press enter in a yaml file. If you have a JSON schema attached to the file and autocomplete name then it should automatically indent underneath the "m"

@eailfly
Copy link
Author

eailfly commented Feb 27, 2020

I'm curious, what's different between I press enter after name: in a yaml and press enter after def some(): in a python file, indent works well in a python file.

@JPinkney
Copy link
Contributor

From reading the docs it looks like this could be implemented using indent rules

@zlmiller
Copy link

zlmiller commented Oct 2, 2020

I'm having a similar issue while writing kubernetes manifests. Using these settings...
image
...when I try to define a rule for an Ingress object, the http suggestion appears, as it should, but when I hit enter, the additional items are inserted with the first non-whitespace character at the given columns.
image
As you can see, it's quite...off...

After playing around and trying all permutations of the relevant editor settings, both language-specific and global, I found these lines in extension.ts:

// Options to control the language client
  const clientOptions: LanguageClientOptions = {
    // Register the server for on disk and newly created YAML documents
    documentSelector: [{ language: 'yaml' }],
    synchronize: {
      // Synchronize these setting sections with the server
      configurationSection: ['yaml', 'http.proxy', 'http.proxyStrictSSL', 'editor.tabSize'],
      // Notify the server about file changes to YAML and JSON files contained in the workspace
      fileEvents: [workspace.createFileSystemWatcher('**/*.?(e)y?(a)ml'), workspace.createFileSystemWatcher('**/*.json')],
    },
  };

This led me to believe that the "editor.tabSize" was being used instead of the same field found inside the "[yaml]" block. Sure enough, I changed the global "editor.tabSize" from 4 to 2, and...voilà! The problem went away.

I'm not 100 percent confident, but it seems like the extension isn't picking up the editor settings for the language defined in the settings with "[yaml]", but only the language server settings which are prefixed w/ yaml (no brackets).

@zlmiller
Copy link

zlmiller commented Oct 2, 2020

After re-reading the initial issue, these aren't actually all that similar. haha 😅

Nonetheless, I think I've found the commit that introduced the problem I'm experiencing: #362

I had been using 0.11.1, and installed 0.11.0. The problem still occurred. I went back to 0.10.0, and it worked as expected.

The change referenced appears to have been made as part of the 0.11.0 release.

@evidolob
Copy link
Collaborator

evidolob commented Oct 2, 2020

@zlmiller I cannot reproduce your problem:
ezgif com-gif-maker

Make sure that you select proper indentation(Spaces) on VSCode status bar:
Screenshot 2020-10-02 at 11 28 20

If you still has problem, please create new issue, we can discuss there.

@zlmiller
Copy link

zlmiller commented Oct 2, 2020

Hmm. Interesting. I presume the settings.json in the gif were the only ones in effect? i.e. no other level (User, Workspace, etc.)

I might just have to take those as a starting point.

@evidolob
Copy link
Collaborator

evidolob commented Oct 5, 2020

settings.json in gif is Workspace settings, I assume that they has bigger priority then User settings

@aeschli
Copy link
Contributor

aeschli commented May 4, 2022

Same request: microsoft/vscode#148528.
This could added with a onEnter rule.
If you come up with something, I'm happy to adopt it in the built-in yaml extension.

@jaro-io
Copy link

jaro-io commented Apr 16, 2023

for everyone still struggling here..

install the yaml extension. and then set editor.formatOnType to true.

@life5ign
Copy link

life5ign commented Dec 4, 2023

I'm pretty frustrated to not have an autoindent after colon enter in YAML; my Vim plugins do this; given that some people in this thread have reported they can't reproduce it, how do we dump and identify the settings that might be causing some of us to have this issue?

@sci-42ver
Copy link

sci-42ver commented Mar 16, 2024

Recently Í also had this problem, but most of other extentions like .lua can work, so it is probably the setting.json error.

Then hinted by this, I use the following config:

    "[yaml]": {
        // "editor.defaultFormatter": "redhat.vscode-yaml", // this will format with one weird result for some yamls sometimes, so Í format manually with only the indentation format when typing.
        "editor.tabSize": 2,
        "editor.autoIndent": "full" // the default setting is "keep"
    }

It works well with the predefined tabSize and will have the following typing behavior:

foo:
  bar: // this line the tab count will be added to 1 based on the past line
    - bar_1 // this line the tab count will be also added
    - bar_2 // this line the tab count will not be also added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants