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

LSP to resolve custom include paths (e.g. Hardhat) #12994

Merged
merged 2 commits into from
Jul 13, 2022

Conversation

christianparpart
Copy link
Member

@christianparpart christianparpart commented May 9, 2022

This PR is WIP, but it will fix #12833 later on.

Big question is, how do we want to tell solc --lsp where to look for include paths. I remember there was some project file format that does include that information, but what was that? @cameel, do you remember?

Checklist:

  • factor our file path resolving in FileRepository: tryResolvePath(.)
  • fix sourceUnitNameToUri() by making use of new path resolver.
  • custom include paths via JSON settings object
  • always add {projectRoot}/node_modules to include paths (vscode-solidity is doing that too and users are used to it)

@cameel
Copy link
Member

cameel commented May 9, 2022

I remember there was some project file format that does include that information, but what was that? @cameel, do you remember?

Do you mean the dappfile (EIP 82)? Or one of the config files actually used by frameworks?

@christianparpart
Copy link
Member Author

I remember there was some project file format that does include that information, but what was that? @cameel, do you remember?

Do you mean the dappfile (EIP 82)? Or one of the config files actually used by frameworks?

ah right thanks! Dappfile is what I remembered, but this time, I in fact meant a framework that introduced a file that is now also supported by another one. I am talking vaguely because I forgot the names. ;-(

I might look into Dappfile though.

@christianparpart
Copy link
Member Author

@cameel if we can't come up with something immediately, what do you think about adding a CLI option, such as --lsp-search-paths PATH,.... NB: We once agreed in explicitly not messing with standard-json or related CLI args, as these are in fact two different topics, IIRC.

@cameel
Copy link
Member

cameel commented May 9, 2022

ah right thanks! Dappfile is what I remembered, but this time, I in fact meant a framework that introduced a file that is now also supported by another one. I am talking vaguely because I forgot the names. ;-(

Oh, you meant remappings.txt (#12603). But it's not really for include paths. It's for remappings (though in practice they get used to get the same effect).

@cameel

This comment was marked as outdated.

@christianparpart
Copy link
Member Author

if we can't come up with something immediately, what do you think about adding a CLI option,

Why not just support --include-paths instead of adding a new arg?

I can do that. thanks. But I am still hoping for some kind of auto-configuration, where users do not need to do too much.

Suppose you are working in more than one project, and they all do not necessarily share the same include paths.

I think we could auto-detect at least the well known frameworks and adjust the include paths accordingly (on top of manually added ones, if added). What do you think, @cameel ?

@christianparpart christianparpart force-pushed the lsp-include-path branch 2 times, most recently from 238692d to 0a4acc5 Compare May 16, 2022 14:17
@christianparpart christianparpart marked this pull request as ready for review May 16, 2022 15:41
@christianparpart christianparpart force-pushed the lsp-include-path branch 2 times, most recently from 91283c4 to 1be4464 Compare May 16, 2022 16:40
Marenz
Marenz previously requested changes May 16, 2022
Copy link
Contributor

@Marenz Marenz left a comment

Choose a reason for hiding this comment

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

In the commit with the descrp. [lsp] Fixes sourceUnitNameToUri() path path resolving in relation to ... …include paths being used.
Maybe one path is enough in the commit message? :P

Changelog.md Outdated Show resolved Hide resolved
libsolidity/lsp/LanguageServer.cpp Outdated Show resolved Hide resolved
libsolidity/lsp/LanguageServer.cpp Show resolved Hide resolved
libsolidity/lsp/LanguageServer.cpp Outdated Show resolved Hide resolved
libsolidity/lsp/LanguageServer.cpp Outdated Show resolved Hide resolved
libsolidity/lsp/LanguageServer.cpp Outdated Show resolved Hide resolved
libsolidity/lsp/LanguageServer.cpp Outdated Show resolved Hide resolved
libsolidity/lsp/FileRepository.cpp Outdated Show resolved Hide resolved
libsolidity/lsp/FileRepository.cpp Show resolved Hide resolved
libsolidity/lsp/FileRepository.cpp Show resolved Hide resolved
libsolidity/lsp/FileRepository.cpp Outdated Show resolved Hide resolved
test/libsolidity/lsp/include-paths/default-include.sol Outdated Show resolved Hide resolved
@cameel

This comment was marked as resolved.

@christianparpart christianparpart changed the base branch from develop to fix/lsp-checker-to-not-bail-on-missing-response July 12, 2022 12:46
Base automatically changed from fix/lsp-checker-to-not-bail-on-missing-response to develop July 12, 2022 13:16
…s added by default.

- Factor out FileRepository's path resolving into own public function.
- Fixes sourceUnitNameToUri() path resolving in relation to include paths being used.
- Adding an solAssert().
- adds nother test for include-paths (bad include)
- Fixes a case on Windows there an ill-formed URI was generated.
- Dropping unnecessary if-branch when translating from sourceUnitName to URI.
@christianparpart christianparpart added the priority review We want this get the review of this PR to a conclusion ASAP. label Jul 12, 2022
@christianparpart christianparpart force-pushed the lsp-include-path branch 3 times, most recently from fab70dc to ad15e3f Compare July 12, 2022 16:23
test/lsp.py Outdated Show resolved Hide resolved
@christianparpart christianparpart force-pushed the lsp-include-path branch 2 times, most recently from 55bfa4d to 209cf59 Compare July 13, 2022 11:49
cameel
cameel previously approved these changes Jul 13, 2022
@christianparpart christianparpart merged commit f686294 into develop Jul 13, 2022
@christianparpart christianparpart deleted the lsp-include-path branch July 13, 2022 12:41
@cameel cameel removed the priority review We want this get the review of this PR to a conclusion ASAP. label Jul 13, 2022
@narghev
Copy link

narghev commented Aug 6, 2022

Hi, just had this problem on nvim with newly installed version of solc using brew.
Version: 0.8.15+commit.e14f2714.Darwin.appleclang

Wanted to check if this is released already or not.

Edit: Checked and the commit with hash e14f2714 thus the v0.8.15 was released on Jun 15th which is before this merge. Is this going to be included in 0.8.16?

@cameel
Copy link
Member

cameel commented Aug 7, 2022

Yes, this will go into 0.8.16, which we are releasing tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LSP: bare imports are not resolved
6 participants