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

feat: Indicate modified buffers #1835

Merged
merged 25 commits into from Dec 31, 2022
Merged

feat: Indicate modified buffers #1835

merged 25 commits into from Dec 31, 2022

Conversation

chomosuke
Copy link
Collaborator

@chomosuke chomosuke commented Dec 18, 2022

closes #1577.

New options and their docs are already completed, I'm opened to feedback on those.

TODOs:

  • highlight_modified
  • modified_placement
    • after
    • before
    • signcolumn
  • show_on_dirs
  • show_on_open_dirs

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Looking good so far.

OK

defaults

    modified = {
      enable = true,
      show_on_dirs = true,
      show_on_open_dirs = false,
      debounce_delay = 50,
    },
    update_focused_file = {
      enable = true,
      debounce_delay = 15,

Manual refresh

:NvimTreeToggle

:NvimTreeClose :NvimTreeOpen

Change directory to a different sibling then back

NOT OK

does not show on opened directory

    modified = {
      enable = true,
      show_on_dirs = true,
      show_on_open_dirs = false,
      debounce_delay = 50,
    },

does not show on any directory

    modified = {
      enable = true,
      show_on_dirs = true,
      show_on_open_dirs = true,
      debounce_delay = 50,
    },

doc/nvim-tree-lua.txt Show resolved Hide resolved
doc/nvim-tree-lua.txt Outdated Show resolved Hide resolved
doc/nvim-tree-lua.txt Outdated Show resolved Hide resolved
doc/nvim-tree-lua.txt Show resolved Hide resolved
lua/nvim-tree.lua Outdated Show resolved Hide resolved
doc/nvim-tree-lua.txt Outdated Show resolved Hide resolved
Refactored to make everything use HighlightedString to remove all the complex `insert_highlight` calculation.
Not tested.
@chomosuke
Copy link
Collaborator Author

chomosuke commented Dec 23, 2022

Test cases:

  • padding
    • empty string
      image
    • long string
      image
  • git, modified placement:
    • signcolumn, signcolumn
      • diagnostics & modified precede git
      • modified precede diagnostics
    • before, before
      image
    • before, after
      image
    • after, before
      image
    • after, after
      image
  • highlight_modified
    • icon
      image Note: had to change the default highlight color to test this properly. By default NvimTreeModifiedFile is green. Like shown above.
    • name
      image
    • all
      image
    • precedence
    • change highlight group color
    • renderer.icons.show.modified = false
  • show_on_dirs = true
    • show_on_open_dirs = false
    • show_on_open_dirs = true

@alex-courtis
Copy link
Member

We could add to base16 when we are done echasnovski/mini.nvim#181

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Looking good, apologies for the delay.

Tested some with the following general cases:

  • git
  • diagnostics
  • symlinks
  • indent markers

Testing all permutations and combinations is not feasible however sampled the following:

  • modified.enabled
  • modified.show_on_dirs
  • modified.show_on_open_dirs
  • highlight_modified = "none"
  • highlight_modified = "icon"
  • highlight_modified = "name"
  • highlight_modified = "all"
  • highlight_modified = "bleh"
  • glyphs.modified = ""
  • glyphs.modified = "X"
  • icons.modified_placement = "after"
  • icons.modified_placement = "before"
  • icons.modified_placement = "signcolumn"
  • icons.show.modified

"Failing" but good enough as they are consistent

  • glyphs.modified = "XY" shows both, missing, same as git and file icons, good enough
  • icons.modified_placement = "bleh" missing, same as git, good enough

TODO

modified = {
enable = false,
show_on_dirs = true,
show_on_open_dirs = false,
Copy link
Member

Choose a reason for hiding this comment

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

Could we perhaps change this to be consistent with git?

      show_on_dirs = true,
      show_on_open_dirs = true,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually wanted to change git & diagnostics to the same as modified because I think that'd be the default that most people want, but didn't cause i thought that'd be breaking.

Idk what is this plugin's stance on changes in default though, if you think it's alright I can make that change in this PR.

In the mean time I'll change modified to be consistent with git for now :).

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'd like to change those defaults, they make more sense. That's what I use.

Users do get upset when we make changes like that so we have avoided doing so.

I am open to trying it again: how about we make a separate PR for those sensible defaults that we can revert if there is upset.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have this idea in my head for a while now. Wanted to open an issue but didn't find time to do investigation deep enough to justify it.
I would like to discuss future of the project and breaking changes moving forward. I wanted to argue in favour of releasing pre-release version with multiple breaking changes: removed/unified functionality, reorganised configuration options, general clean up. I think project could greatly benefit from refactor without worrying about breaking changes. It would then be released as version 2 for example. Would there be any appetite for that at all?

Copy link
Member

Choose a reason for hiding this comment

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

reorganised configuration options, general clean up

Yes. git.ignore not being in filters. renderer too large. diagnostics.icons not in icons.glyphs. Some root options not in view or their own section.

I would like to discuss future of the project and breaking changes moving forward.

We can break things in a controlled manner that will result in a better experience. We are also good at refactoring options, although we don't use it much.

I wanted to argue in favour of releasing pre-release version with multiple breaking changes

It would then be released as version 2 for example.

Many lua plugins and packer are getting very good at handling versions. I think it is time.

master could remain as "version 1" to avoid interruptions to users, however we could add devel, weekly etc. along with stable, stable-2, stable-2.1, stable-2.1.3 etc. I like SEMVER.

Copy link
Member

Choose a reason for hiding this comment

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

I did discover an interesting pattern with lualine:

User is prompted to run :LualineNotices when there is a configuration problem.

theme(base16): nvim-base16 is not currently present in your runtimepath, make sure it is properly installed, fallback to default colors.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's great to hear. Let's open a dedicated issue to discuss it further.

Copy link
Member

Choose a reason for hiding this comment

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

doc/nvim-tree-lua.txt Show resolved Hide resolved
lua/nvim-tree/renderer/components/padding.lua Show resolved Hide resolved
doc/nvim-tree-lua.txt Show resolved Hide resolved
if not git_icons_and_hl_groups then
---@class HighlightedString
---@field str string
---@field hl string|nil
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for starting this documentation pattern. We should use it more.

sumneko_lua gives me a warning however it does that for other lua code. I might look at putting a suppression in.

20221230_171338 1052x253

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmmm interesting, it doesn't give me any warnings. But maybe putting in suppression in .luarc.json is a good idea for this one.

Copy link
Member

Choose a reason for hiding this comment

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

The problem was on my end... I was putting the current directory in the workspace twice.

I've actually managed to remove all the suppressions: e322fbb

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Last one:

All defaults but modified = "[+]",

Error executing vim.schedule lua callback: ...vt-dev/site/pack/packer/start/packer.nvim/lua/packer.lua:359: Vim(lua):E5108: Error executing lua Vim:E239: Invalid sign text: [+]
stack traceback:
        [C]: in function 'sign_define'
        ...start/dev/lua/nvim-tree/renderer/components/modified.lua:19: in function 'setup_signs'
        ...start/dev/lua/nvim-tree/renderer/components/modified.lua:36: in function 'setup'
        ...te/pack/packer/start/dev/lua/nvim-tree/renderer/init.lua:113: in function 'setup'
        /tmp/nvt-dev/site/pack/packer/start/dev/lua/nvim-tree.lua:828: in function 'setup'
        /home/alex/.local/share/nvim/nvt-dev.lua:34: in function 'setup'
        [string ":lua"]:1: in main chunk
        [C]: in function 'cmd'
        ...vt-dev/site/pack/packer/start/packer.nvim/lua/packer.lua:359: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
        [C]: in function 'cmd'
        ...vt-dev/site/pack/packer/start/packer.nvim/lua/packer.lua:359: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Happens for git and diagnostics too.

Proposal:

  • Only call vim.fn.sign_define if the user has specified "signcolumn"
  • Trim the glyph to 2 characters

@chomosuke
Copy link
Collaborator Author

@alex-courtis Sadly, because lua dose not do utf8 string properly. We can't determine the length of a string or trim a string without some dependency such as https://github.com/uga-rosa/utf8.nvim. I've also tried to pass the string via nvim_eval to vim script and trim it there but had no luck.

@alex-courtis
Copy link
Member

@alex-courtis Sadly, because lua dose not do utf8 string properly. We can't determine the length of a string or trim a string without some dependency such as https://github.com/uga-rosa/utf8.nvim. I've also tried to pass the string via nvim_eval to vim script and trim it there but had no luck.

In that case, we will have to go with the first option:

  • Only call vim.fn.sign_define if the user has specified "signcolumn"

It is failing if you specify many characters even when modified.enabled = false

I really want to be able to use [+] "after" ;)

@chomosuke
Copy link
Collaborator Author

OH YEAH sure, I forgot that option existed after trying so hard to do the second one haha.

@chomosuke chomosuke requested review from alex-courtis and removed request for gegoune December 31, 2022 04:43
@alex-courtis
Copy link
Member

The note is not enough...

Try running with all defaults and glyphs.modified = "XXX"

@chomosuke
Copy link
Collaborator Author

whoops sorry, forgot to push.

@alex-courtis
Copy link
Member

awesome

    .hooks
    doc [+]
    lua
      nvim-tree
       nvim-tree.lua [+]
    scripts

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

I will enjoy this.

@alex-courtis alex-courtis merged commit dcc344c into master Dec 31, 2022
@chomosuke chomosuke deleted the feat-modified-buffers branch December 31, 2022 04:54
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.

Buffer Modified Icon / Highlight As Per Git / Diagnostics
3 participants