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

Weird issue with require #452

Closed
sewbacca opened this issue Mar 16, 2021 · 10 comments
Closed

Weird issue with require #452

sewbacca opened this issue Mar 16, 2021 · 10 comments
Labels
bug Something isn't working

Comments

@sewbacca
Copy link
Contributor

Describe the bug
Sometimes, when i work on a project for a longer time, the language server seems to forget require paths in my current workspace.
Consider this file structure (mine is larger) :

file: ./.vscode/settings.json
content:
...
	"Lua.runtime.path": [
		"modules/?.lua",
		"modules/?/init.lua",
		"modules/?/?.lua"
	],
	/* Attempt to fix weird require not resolving files issues */
	"Lua.workspace.maxPreload": 1000000000,
	"Lua.workspace.preloadFileSize": 1000000000,
...

...
file ./modules/file.lua
content:
module = { }
function module.foo() end
return module

file: ./modules/complicated.lua
content:
local file = requrie "file"

file: ...

when I open vscode with no file opened and then open complicated.lua, file won't get any hints. However if i open file.lua and then go back in complicated.lua it suddenly knows its existence and then shows all hints again.

To Reproduce
Thats the problem, I don't know how to reproduce this problem, since all attempts failed and the server could resolve any path. I tried to delete ~/.config/Code/User/workspaceStorage to delete any malformed caches, but the problem seems to persist. Whenever I need autocompletion for a specific file, first i need to open that file.

Environment (please complete the following information):

  • OS: Kubuntu
  • Client: VSCode

Any ideas what could cause that problem?

@sumneko
Copy link
Collaborator

sumneko commented Mar 16, 2021

@sewbacca
Copy link
Contributor Author

I posted the logs here. (For protocol: I did replaced all occurences of my home directory (/home/<name>) with ~.)
Look at those lines

[14:10:56.329][debug][#0:script.provider.diagnostic:223]: publishDiagnostics	file:///tmp/vscode/Rudi/usr/modules/uri.lua	1
[14:10:56.330][debug][#0:script.provider.diagnostic:340]: 全文诊断耗时:	0.071684
[14:11:02.125][debug][#0:script.provider.provider:258]: didClose	file:///tmp/vscode/Rudi/usr/modules/uri.lua
[14:11:02.167][debug][#0:script.provider.provider:246]: didOpen	file:///tmp/vscode/Rudi/.vscode/modules/cc/expect.lua
[14:11:02.262][debug][#0:script.provider.diagnostic:340]: 全文诊断耗时:	0.003776
[14:11:07.526][debug][#0:script.provider.provider:258]: didClose	file:///tmp/vscode/Rudi/.vscode/modules/cc/expect.lua
[14:11:07.602][debug][#0:script.provider.provider:246]: didOpen	file:///tmp/vscode/Rudi/usr/modules/uri.lua
[14:11:07.690][debug][#0:script.provider.diagnostic:223]: publishDiagnostics	file:///tmp/vscode/Rudi/usr/modules/uri.lua	1

Allmost at the end of the log.
First I open uri.lua, see no hints (hovering mouse), then open expect.lua and then uri.lua again and see hints.

@sumneko
Copy link
Collaborator

sumneko commented Mar 16, 2021

It seems that the file search failed. A known problem is that if there is a soft link in your directory, I will get into an endless loop and may ignore the entire directory.

Please modify the code manually to check if an exception is thrown in these two places:
https://github.com/sumneko/lua-language-server/blob/268cfa9dd50292269c4c3bcc40093b54c6727bfa/script/workspace/workspace.lua#L45
https://github.com/sumneko/lua-language-server/blob/268cfa9dd50292269c4c3bcc40093b54c6727bfa/script/workspace/workspace.lua#L60

I can reply you tomorrow

@sewbacca
Copy link
Contributor Author

sewbacca commented Mar 16, 2021

I checked and couldn't find any soft links inside my project, nor inside my library. The only link I'm using is to reference my project to another location, so it can be used there and edited in my projects folder, but this link is not inside my project.
I'll check those two places and post my results later.

@sewbacca
Copy link
Contributor Author

sewbacca commented Mar 16, 2021

So i modified the code to the following:

    type = function (path)
        local result
        local ok, err = pcall(function ()
            if fs.is_directory(fs.path(path)) then
                result = 'directory'
            else
                result = 'file'
            end
        end)
        if not ok then
            log.error("pcall 1 failure", err)
        else
            log.info("pcall 1 success")
        end
        return result
    end,
    list = function (path)
        local fullPath = fs.path(path)
        if not fs.exists(fullPath) then
            return nil
        end
        local paths = {}
        local ok, err = pcall(function ()
            for fullpath in fullPath:list_directory() do
                paths[#paths+1] = fullpath:string()
            end
        end)
        if not ok then
            log.error("pcall 2 failure", err)
        else
            log.info("pcall 2 success")
        end
        return paths
    end

Here is my resulting log file.
It seems like there aren't any issues. I repeated the process as following:

  1. Open uri.lua
  2. Press f12 on expect -> No definition found
  3. Goto expect.lua
  4. Goto uri.lua
  5. Press f12 on expect -> expect.lua opens

EDIT:
P.S. I noticed something about gitignore directory. Just wanted to mention, that for modules, which are not ignored, the same error occurs. However i posted the log before testing this case.

@sumneko
Copy link
Collaborator

sumneko commented Mar 17, 2021

From your log, the file file:///tmp/vscode/Rudi/.vscode/modules/cc/expect.lua is both ignored by .gitignore: /.vscode/modules and Lua.workspace.ignoreDir: modules.

@sewbacca
Copy link
Contributor Author

sewbacca commented Mar 17, 2021

Okay, so I thought ignoreDir uses paths relative to working directory, not to any path. I wanted to ignore /modules not every folder called modules. Also I thought, that .gitignore shouldn't be the problem, since I used /.vscode/modules for documentation purposes only, which shouldn't be under version control.
However, I removed the ignoreDir property completly and I tested this time only files that are under version control, and the error still persists. Here is my log.

Test process:

  1. Opened redrudi.lua
  2. F12 on uri -> No result
  3. Opened uri.lua
  4. Opened redrudi.lua
  5. F12 on uri -> uri.lua opens

@sumneko
Copy link
Collaborator

sumneko commented Mar 17, 2021

Here is a bug in parsing gitignore.

You have the following in your gitignore:

/*
!/usr

My handling of the content was wrong, which caused the entire directory to be ignored.

@sumneko sumneko added the bug Something isn't working label Mar 17, 2021
@sewbacca
Copy link
Contributor Author

sewbacca commented Mar 17, 2021

Ah yes, I forgot, that I used this feature. My program is creating a lot of directories and files, which shouldn't be version controlled, that's why I ignored everything und unignored (is there a word for that?) only where my files are going.
Thanks alot for all your efforts, I really like this extension :)

I tried to remove !/usr and /* and now it works. I get all the hints, I need from require. For now I avoid that feature as a workarround.

P.S. What do you think about installing docs locally and ignoring them in .gitignore? In this case I would still want to get recommendations from those directories. And if I really wish to ignore certain directories, then I simply add them in settings.json under ignoreDir. And what about singular files, because it is not possible to add them in ignoreDir?

@sumneko
Copy link
Collaborator

sumneko commented Mar 17, 2021

Ah yes, I forgot, that I used this feature. My program is creating a lot of directories and files, which shouldn't be version controlled, that's why I ignored everything und unignored (is there a word for that?) only where my files are going.
Thanks alot for all your efforts, I really like this extension :)

I tried to remove !/usr and /* and now it works. I get all the hints, I need from require. For now I avoid that feature as a workarround.

P.S. What do you think about installing docs locally and ignoring them in .gitignore? In this case I would still want to get recommendations from those directories. And if I really wish to ignore certain directories, then I simply add them in settings.json under ignoreDir. And what about singular files, because it is not possible to add them in ignoreDir?

Here is a setting Lua.workspace.useGitIgnore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants