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

Configuration "include_dirs" doesn't work with 'include_lib" that includes a relative path #762

Open
amiramix opened this issue Jun 7, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@amiramix
Copy link

amiramix commented Jun 7, 2020

Describe the bug

The project consists of a few OTP releases with applications, dependencies, and libraries in various folders. The configuration file is placed in the root folder for those releases, e.g.:

erlang_ls.config
erlector_rel/_erlector/lib/... (a few custom OTP applications)
erlector_rel/_erlector/lib/erlector/src/etr_api.erl (a specific file where erlang_ls can't find include)
erlector_rel/_erlector/lib/yolf/include/yolf.hrl (a specific file included in etr_api.erl above)
erlector_re/_erlector/deps/... (few rebar dependencies)

The configuration file is as follows

g@venus:~/work % cat erlang_ls.config 
apps_dirs:
  - "erlector_rel/_erlector/deps/*"
deps_dirs:
  - "erlector_rel/_erlector/lib/*"
include_dirs:
  - "erlector_rel/_erlector/lib"
  - "erlector_rel/_erlector/deps"

The 'etr_api.erl' has the following include in line 44 which erlang_ls reports as not valid:

-include_lib("yolf/include/yolf.hrl").

Diagnostic logs show the following request:

"textDocument": {
  "uri": "file:///home/g/work/erlector_rel/_erlector/lib/erlector/src/etr_api.erl"
},

And the diagnostic error:

{
  "range": {
    "start": {
      "line": 43,
      "character": 0
    },
    "end": {
      "line": 44,
      "character": 0
    }
  },
  "severity": 1,
  "source": "Compiler",
  "message": "can\u0027t find include lib \"yolf/include/yolf.hrl\""
},

The interesting bit is that when hovering over the error the diagnostic dialog shows that the file is present:

can't find include lib "yolf/include/yolf.hrl"
/home/g/work/erlector_rel/_erlector/lib/yolf/include/yolf.hrl
Size: 2.08 kB
Type: Erlang Header (Erlang)
Modified: 06/06/20 13:06
Created: 06/06/20 13:06

g@venus:~/work % ls -l erlector_rel/_erlector/lib/yolf/include/yolf.hrl 
-rw-r--r--  1 g  g  2080  6 Jun 13:06 erlector_rel/_erlector/lib/yolf/include/yolf.hrl

To Reproduce

Add "include_lib" to an .erl file that includes the file from a relative folder using a path (see description above).

Expected behavior

The "include_lib" is correctly resolved and loaded by the compiler and not reported as "Can't find include lib".

Actual behavior

The "include_lib" isn't loaded and the source file shows an "erlang_ls" error that the file can't be included. The file compiles fine.

Context

  • erlang_ls version (tag/sha): 0.4.0+build.1161.ref64313bb
  • Editor used: IntelliJ
  • LSP client used: erlang_ls
@amiramix amiramix added the bug Something isn't working label Jun 7, 2020
luos added a commit to luos/erlang_ls that referenced this issue Jun 10, 2020
If an erlang file has a hrl included the compiler diagnostics raises an
error because it is not included in the operation.

Fix needs that the dependency directory is configured correctly.

Related erlang-ls#762
luos added a commit to luos/erlang_ls that referenced this issue Jun 10, 2020
If an erlang file has a hrl included the compiler diagnostics raises an
error because it is not included in the operation.

Fix needs that the dependency directory is configured correctly.

Related erlang-ls#762
@luos
Copy link
Contributor

luos commented Jun 10, 2020

Hi,

I think I have a same / similar problem, for me there is an include statement at the top of the file for a .hrl, but compile:file does not have the {i, Dir} as an argument, which makes this error come up.

This is an Erlang.mk project. I will open a PR with the fix, but I am not sure if it is the correct fix, because it needs that I add deps directory under deps_dirs in the erlang_ls.config file.

Link to the PR:
#764

Let me know what you think

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