GithubHelp home page GithubHelp logo

Comments (5)

zeertzjq avatar zeertzjq commented on September 27, 2024

Cannot reproduce. Maybe it only happens in WSL?

from neovim.

hexium310 avatar hexium310 commented on September 27, 2024

I tried it on Mac and reproduced it. Did you wait a few seconds for the LSP to launch after opening empty.lua?

on WSL
wsl_expand

on Mac
mac_expand

from neovim.

zeertzjq avatar zeertzjq commented on September 27, 2024

Oops, I misspelled .editorconfig. It's strange that this bug only happens when there is a .editorconfig file present.

from neovim.

hexium310 avatar hexium310 commented on September 27, 2024

Actually, it does not occur when there is a .editorconfig file, but when I am under the directory existing root marker files (or directories) for LSP. It occurs when there is a .git directory or editing root_marker such as local root_markers = { 'minimal.lua' } in minimal.lua.

from neovim.

mfussenegger avatar mfussenegger commented on September 27, 2024

I think this is kinda expected. The behavior of expand('%') depends on how the buffer was added.
When neovim receives diagnostics from the language server it calls bufadd for the file uris/filenames

E.g. compare:

  • Open nvim without file
  • :call bufadd("/absolute/path/to/file")
  • :e to/file
  • :echo expand("%")

With

  • Open nvim without file
  • :call bufadd("relative/path")
  • :e relative/path
  • :echo expand("%")

Regarding .git/.editorconfig: .git is a folder and .editorconfig is a file so you get a different root_dir. Compare vim.fn.fnamemodify(".git/", ":p:h") with vim.fn.fnamemodify(".editorconfig", ":p:h") in a folder where both exists. I use something like this because of that difference:

function M.find_root(markers, path)
  path = path or api.nvim_buf_get_name(0)
  local match = vim.fs.find(markers, { path = path, upward = true })[1]
  if match then
    local stat = vim.loop.fs_stat(match)
    if stat and stat.type == "directory" then
      return vim.fn.fnamemodify(match, ':p:h:h')
    end
    return vim.fn.fnamemodify(match, ':p:h')
  end
  return nil
end

from neovim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.