Skip to content

fix diagnostics showing up on file/dir with same prefix #1832

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 4 commits into from
Dec 23, 2022

Conversation

chomosuke
Copy link
Collaborator

If A's path is B's prefix, then diagnostics in B will show up in both of them. For example, if there's diagnostics for lua/nvim-tree.lua, lua/nvim-tree/ will also show diagnostics even though non of it's children have any.

This PR fixes that.

@chomosuke
Copy link
Collaborator Author

Hmmmmm now that I look at it vim.fn.fnamemodify isn't really cleaner? I don't have a windows machine though so I don't know if all the vim.fn.fnamemodify are necessary and if utils.canonical_path are still necessary. I'd appreciate if someone with a windows machine can test that. I don't really have a strong preference between fnamemodify and gsub though so I'd leave it up to @alex-courtis to decide. Pls revert the last commit before you merge if you prefer gsub :).

@alex-courtis
Copy link
Member

Unfortunately I am out of time; I'll get to this one on the weekend.

@alex-courtis
Copy link
Member

alex-courtis commented Dec 23, 2022

Hmmmmm now that I look at it vim.fn.fnamemodify isn't really cleaner? I don't have a windows machine though so I don't know if all the vim.fn.fnamemodify are necessary and if utils.canonical_path are still necessary. I'd appreciate if someone with a windows machine can test that. I don't really have a strong preference between fnamemodify and gsub though so I'd leave it up to @alex-courtis to decide. Pls revert the last commit before you merge if you prefer gsub :).

startswith is very useful. I should use that more.

It looks like we do need canonical_path, if just for the case of the drive letter. I'm not sure that is necessary however I cannot test.

@alex-courtis
Copy link
Member

Looks like startswith is a winner: it doesn't match any vim or lua patterns. Much simpler than string.find plain.

  local needle = "/cc"
  local haystack = "/cc/dd/ee"

  log.line("dev", "needle '%s' haystack '%s' startswith   %s", needle, haystack, vim.startswith(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' vim.fn.match %s", needle, haystack, vim.fn.match(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.match %s", needle, haystack, string.match(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.find  %s", needle, haystack, string.find(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.find  %s", needle, haystack, string.find(haystack, needle, 1, true))

  log.line("dev", "")

  needle = "c:\\cc"
  haystack = "c:\\cc\\dd\\ee"

  log.line("dev", "needle '%s' haystack '%s' startswith   %s", needle, haystack, vim.startswith(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' vim.fn.match %s", needle, haystack, vim.fn.match(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.match %s", needle, haystack, string.match(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.find  %s", needle, haystack, string.find(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.find  %s", needle, haystack, string.find(haystack, needle, 1, true))

  log.line("dev", "")

  needle = "c:\\.c"
  haystack = "c:\\cc\\dd\\ee"

  log.line("dev", "needle '%s' haystack '%s' startswith   %s", needle, haystack, vim.startswith(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' vim.fn.match %s", needle, haystack, vim.fn.match(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.match %s", needle, haystack, string.match(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.find  %s", needle, haystack, string.find(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.find  %s", needle, haystack, string.find(haystack, needle, 1, true))

  log.line("dev", "")

  needle = "c:\\%ac"
  haystack = "c:\\cc\\dd\\ee"

  log.line("dev", "needle '%s' haystack '%s' startswith   %s", needle, haystack, vim.startswith(haystack, needle))
  -- log.line("dev", "needle '%s' haystack '%s' vim.fn.match %s", needle, haystack, vim.fn.match(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.match %s", needle, haystack, string.match(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.find  %s", needle, haystack, string.find(haystack, needle))
  log.line("dev", "needle '%s' haystack '%s' string.find  %s", needle, haystack, string.find(haystack, needle, 1, true))
[2022-12-23 11:56:13] [dev] needle '/cc' haystack '/cc/dd/ee' startswith   true
[2022-12-23 11:56:13] [dev] needle '/cc' haystack '/cc/dd/ee' vim.fn.match 0
[2022-12-23 11:56:13] [dev] needle '/cc' haystack '/cc/dd/ee' string.match /cc
[2022-12-23 11:56:13] [dev] needle '/cc' haystack '/cc/dd/ee' string.find  1
[2022-12-23 11:56:13] [dev] needle '/cc' haystack '/cc/dd/ee' string.find  1
[2022-12-23 11:56:13] [dev]
[2022-12-23 11:56:13] [dev] needle 'c:\cc' haystack 'c:\cc\dd\ee' startswith   true
[2022-12-23 11:56:13] [dev] needle 'c:\cc' haystack 'c:\cc\dd\ee' vim.fn.match -1
[2022-12-23 11:56:13] [dev] needle 'c:\cc' haystack 'c:\cc\dd\ee' string.match c:\cc
[2022-12-23 11:56:13] [dev] needle 'c:\cc' haystack 'c:\cc\dd\ee' string.find  1
[2022-12-23 11:56:13] [dev] needle 'c:\cc' haystack 'c:\cc\dd\ee' string.find  1
[2022-12-23 11:56:13] [dev]
[2022-12-23 11:56:13] [dev] needle 'c:\.c' haystack 'c:\cc\dd\ee' startswith   false
[2022-12-23 11:56:13] [dev] needle 'c:\.c' haystack 'c:\cc\dd\ee' vim.fn.match -1
[2022-12-23 11:56:13] [dev] needle 'c:\.c' haystack 'c:\cc\dd\ee' string.match c:\cc
[2022-12-23 11:56:13] [dev] needle 'c:\.c' haystack 'c:\cc\dd\ee' string.find  1
[2022-12-23 11:56:13] [dev] needle 'c:\.c' haystack 'c:\cc\dd\ee' string.find  nil
[2022-12-23 11:56:13] [dev]
[2022-12-23 11:56:13] [dev] needle 'c:\%ac' haystack 'c:\cc\dd\ee' startswith   false
[2022-12-23 11:56:13] [dev] needle 'c:\%ac' haystack 'c:\cc\dd\ee' string.match c:\cc
[2022-12-23 11:56:13] [dev] needle 'c:\%ac' haystack 'c:\cc\dd\ee' string.find  1
[2022-12-23 11:56:13] [dev] needle 'c:\%ac' haystack 'c:\cc\dd\ee' string.find  nil

@alex-courtis
Copy link
Member

Hmmmmm now that I look at it vim.fn.fnamemodify isn't really cleaner?

The key part is the node.nodes test.

gsub works even for crazy paths like /tmp/bleh\bleh

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.

Tested OK:
nvim-tree.lua/lua show_on_dirs show_on_open_dirs

  • false false
  • true false
  • false true
  • true true

nvim-tree/lua\lua
as above

@alex-courtis alex-courtis merged commit 3000797 into master Dec 23, 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.

2 participants