Skip to content

#1166 validate user's options #1177

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

Merged
merged 9 commits into from
Apr 24, 2022
Merged

#1166 validate user's options #1177

merged 9 commits into from
Apr 24, 2022

Conversation

alex-courtis
Copy link
Member

@alex-courtis alex-courtis commented Apr 18, 2022

closes #1166

Quite easy: validate user's options against DEFAULT_OPTS.

@geoboom I would be very grateful if you can test, test, test.

Edit: apologies @geoboom I meant to ask @gegoune to test this one ;)

Copy link
Member

@kyazdani42 kyazdani42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the implementation :)

@gegoune
Copy link
Collaborator

gegoune commented Apr 21, 2022

Got unknown option: filters.custom.1 so either this PR needs rebasing or me asking for that feature was not unreasonable after all. :)

Edit: according to readme filters.custom is a table, so it should not warn me about it, should it?

@kyazdani42
Copy link
Member

i think the ignore list might be incorrect ?

@gegoune
Copy link
Collaborator

gegoune commented Apr 21, 2022

Screenshot 2022-04-21 at 21 18 04

In terms of notification itself seems like there is extra empty line.

@gegoune
Copy link
Collaborator

gegoune commented Apr 21, 2022

i think the ignore list might be incorrect ?

  filters = {
    custom = { '.git', 'node_modules', '.cache', '.DS_Store' },
  },

Nothing really fancy in there I think.

@kyazdani42
Copy link
Member

not yours @gegoune , the one in the PR ^^

@alex-courtis
Copy link
Member Author

alex-courtis commented Apr 22, 2022

Got unknown option: filters.custom.1 so either this PR needs rebasing or me asking for that feature was not unreasonable after all. :)

Edit: according to readme filters.custom is a table, so it should not warn me about it, should it?

That is definitely not working correctly. It should go in NO_VALIDATE_OPTS.

However, reporting an itable index is also wrong and needs to be fixed.

@alex-courtis
Copy link
Member Author

alex-courtis commented Apr 22, 2022

In terms of notification itself seems like there is extra empty line.

That can be fixed.

@gegoune how is that message formatted? I've been testing with nvt-min and plain text formatting. Maybe share your config?

@gegoune
Copy link
Collaborator

gegoune commented Apr 22, 2022

@alex-courtis it's default config for rcarriga/nvim-notify.

@alex-courtis
Copy link
Member Author

alex-courtis commented Apr 23, 2022

Hardened and rewrote:

  • removed ignore list; handle empty default tables during validate
  • deletes invalid options
  • checks all options in each table after a failure
  • use one line for message; newlines upset everything
  • refactored the legacy migrations / warnings to happen before validation
  • system_open.cmd default is now "" to avoid the nil value problem

Copy link
Member

@kyazdani42 kyazdani42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice improvement :) thanks !

@kyazdani42
Copy link
Member

@gegoune does this work now for you as expected ?

@gegoune
Copy link
Collaborator

gegoune commented Apr 23, 2022

@gegoune does this work now for you as expected ?

Yes, it does. Looks good now and detects incorrect keys, at least handful that I tried Thanks!

@alex-courtis
Copy link
Member Author

@gegoune does this work now for you as expected ?

Yes, it does. Looks good now and detects incorrect keys, at least handful that I tried Thanks!

Thanks for the testing @gegoune

I think we can merge now.

@@ -324,6 +324,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
view = {
width = 30,
height = 30,
hide_root_folder = false,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an extra hide_root_folder in the above table. It doesn't appear to be used, so I deleted it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, it wasn't in the right place !

@kyazdani42 kyazdani42 merged commit 5bbd3a0 into master Apr 24, 2022
@gegoune
Copy link
Collaborator

gegoune commented Apr 24, 2022

Thanks for that! Hopefully it will prevent configuration-issue issues.

@eeeXun
Copy link
Contributor

eeeXun commented Apr 24, 2022

I set up width with function. Not working anymore?

require("nvim-tree").setup({
    view = {
        width = function()
            return math.floor(vim.o.columns * 0.225)
        end,
    }
})

Warning

[NvimTree] invalid option: view.width expected: number actual: function

kyazdani42 added a commit that referenced this pull request Apr 24, 2022
@alex-courtis
Copy link
Member Author

alex-courtis commented Apr 25, 2022

[NvimTree] invalid option: view.width expected: number actual: function

Interesting use case: functions for configuration options is something I would never have considered.
+ great user flexibility
- poor stability
- unpredictable behaviour when a varying value is used

Alternatives:

  1. No change: do not allow functions
  2. Allow a function when the type is not a table
  3. Allow a function always
  4. Provide a proper mechanism for this, something like view.width_ratio

I like flexibility; 2 is a good compromise. We would need to document that with warnings and a rule that bugs cannot be raised when such functions are used. @kyazdani42 ?

Edit: I have implemented 3: #1195 It might be useful to allow functions as tables for, say, diagnostics.icons

@gegoune
Copy link
Collaborator

gegoune commented Apr 25, 2022

How about 'allow functions but require returned value of specific type and validate it'?

@alex-courtis
Copy link
Member Author

How about 'allow functions but require returned value of specific type and validate it'?

That would be great, have you got a specific idea on how we would do this?

The user could do anything in that function; I don't think we could validate it by executing it, as it may throw an exception when run at plugin startup.

@gegoune
Copy link
Collaborator

gegoune commented Apr 25, 2022

Ah, that's a good point. Can't really think of a solution here.

@kyazdani42
Copy link
Member

there is only a function available for the tree width / height but the implementation for the validation is good enough :)

@eeeXun
Copy link
Contributor

eeeXun commented Apr 27, 2022

Maybe provide an option like relative_width/relative_height. If true, then the number of width/height should be percentage of columns/lines. If false, the it should be actual columns/lines.

@kyazdani42
Copy link
Member

you can pass in '40%' and it will adapt to the number of columns.

Almo7aya pushed a commit to Almo7aya/nvim-tree.lua that referenced this pull request Oct 11, 2022
Almo7aya pushed a commit to Almo7aya/nvim-tree.lua that referenced this pull request Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate configuration against schema
4 participants