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

Changing TextEditor.options issues #2797

Closed
SamVerschueren opened this issue Feb 8, 2016 · 8 comments · Fixed by #2935
Closed

Changing TextEditor.options issues #2797

SamVerschueren opened this issue Feb 8, 2016 · 8 comments · Fixed by #2935
Assignees
Labels
verified Verification succeeded
Milestone

Comments

@SamVerschueren
Copy link
Contributor

We are working on the EditorConfig plugin and we have issues regarding TextEditor.options.

Users don't have to specify values for let's say indent_style. Let's take the following .editorconfig

root = true

[*]
indent_style = tab

[{package.json,*.yml}]
indent_style = space
indent_size = 2

And my VSCode settings file looks like this

{
    "editor.insertSpaces": "auto",
    "editor.tabSize": "auto"
}

If I open package.json, the style should be set to space and the indent size to 2. If I open index.js, it should set the style to tab and take the global setting (which is auto) so it should be calculated by VS Code itself. At the moment this is not possible. Because you have to overwrite the entire object which prevents auto-calculating the indent size.

@alexandrudima I think you are in charge for something like this :)?

@SamVerschueren
Copy link
Contributor Author

These are my findings. Please let me know if I'm wrong :).

So internally VS Code has some decision check wether it should recalculate the settings for a file in the text editor. Based on some debugging, it looks like the decision looks like this.

  • Is the options object still referring to the initial options object?
    -> YES: No plugin changed the settings so recalculate them based on the user settings
    -> NO: Do nothing as someone altered the object

Because when I only change one value textEditor.options.insertSpaces = true, it still takes my global VS Code settings because (in my opinion) the options object is still referring to the initial options object and thus is not changed.

This is how this issue can be resolved. Values passed in as undefined should be calculated by VS Code (based upon the user settings).

textEditor.options = {
    insertSpaces: true,
    tabSize: undefined
};

// OR

textEditor.options = {
    insertSpaces: true
};

If my global tabSize settings is set to auto, VS Code will determine the tab size for me based on the current file being opened. Same goes for insertSpaces.

@jednano
Copy link

jednano commented Feb 9, 2016

@SamVerschueren you can get the right GitHub code coloring for .editorconfig files by using the ini file type, see?

root = true

[*]
indent_style = tab

[{package.json,*.yml}]
indent_style = space
indent_size = 2

@SamVerschueren
Copy link
Contributor Author

@jedmao Thanks :)

@SamVerschueren
Copy link
Contributor Author

@alexandrudima This issue is thoroughly discussed here editorconfig/editorconfig-vscode#3

@SamVerschueren
Copy link
Contributor Author

@alexandrudima It looks like I found a solution in editorconfig/editorconfig-vscode#5.

It looks like the TextEditorOptions interface is defined like

interface TextEditorOptions {
    tabSize: number,
    insertSpaces: boolean
}

Which makes it not possible to provide auto as value for either one of the properties. But actually, it is perfectly valid to provide auto as VS Code will then auto calculate the value for that property. So I guess a solution for this would be to update that interface.

@jednano
Copy link

jednano commented Feb 11, 2016

For the record, you're referring to these lines.

Would Microsoft be willing to update this interface or is there a good reason they don't use union types for these settings?

@SamVerschueren
Copy link
Contributor Author

Did a PR #2935

I guess they will accept it as I don't see any reason to not allow strings.

alexdima added a commit that referenced this issue Feb 19, 2016
fix TextEditorOptions declaration - fixes #2797
@alexdima
Copy link
Member

Thank you for the PR! 👍

I went a bit further to try to clarify things:

export interface TextEditorOptions {

        /**
         * The size in spaces a tab takes. This is used for two purposes:
         *  - the rendering width of a tab character;
         *  - the number of spaces to insert when [insertSpaces](#TextEditorOptions.insertSpaces) is true.
         * When getting a text editor's options, this property will always be a number (resolved).
         * When setting a text editor's options, this property is optional and it can be a number or `"auto"`.
         */
        tabSize?: number | string;

        /**
         * When pressing Tab insert [n](#TextEditorOptions.tabSize) spaces.
         * When getting a text editor's options, this property will always be a boolean (resolved).
         * When setting a text editor's options, this property is optional and it can be a boolean or `"auto"`.
         */
        insertSpaces?: boolean | string;
    }

@alexdima alexdima added this to the Feb 2016 milestone Feb 19, 2016
@alexdima alexdima added the verified Verification succeeded label Feb 26, 2016
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants