-
Notifications
You must be signed in to change notification settings - Fork 6.2k
allow setting remappings on lsp server init #13423
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
Conversation
Many thanks for your contribution @chrisfarms. We will take a close look at your work. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sure you did your own interactive tests to make sure it all works as expected.
But maybe we also have that automatically tested as part of the still young LSP CI tests.
For that you might want to look at test/lsp.py
and its companion test dir test/libsolidity/lsp/
. In case of concerns, @Marenz can be of great help with respect to that. :)
Thanks, addressed your review comments. Will take a look at the lsp.py tests shortly (had not spotted those tests) 👍 |
added a very basic case to the python lsp tests |
309477c
to
193d3b8
Compare
I rebased the PR to the latest |
@chrisfarms I have been taking over this PR to finish the review, simply applying @leonardoalt's comments & adding a changelog item. I hope you don't mind. |
🙏 don't mind at all, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need some clarification
877e5b9
to
d66c0d9
Compare
d0b55ec
to
73c097e
Compare
Adding @cameel for the final review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only found minor stuff. Overall the feature seems sound.
if ( | ||
jsonPath.isObject() && | ||
jsonPath.get("context", "").isString() && | ||
jsonPath.get("prefix", "").isString() && | ||
jsonPath.get("target", "").isString() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we report an error on unexpected keys?
@@ -1534,6 +1541,70 @@ def test_custom_includes(self, solc: JsonRpcProcess) -> None: | |||
self.expect_equal(len(diagnostics), 1, "no diagnostics") | |||
self.expect_diagnostic(diagnostics[0], code=2018, lineNo=5, startEndColumns=(4, 62)) | |||
|
|||
def test_remapping_wrong_paramateres(self, solc: JsonRpcProcess) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_remapping_wrong_paramateres(self, solc: JsonRpcProcess) -> None: | |
def test_remapping_wrong_parameters(self, solc: JsonRpcProcess) -> None: |
Also, something like test_remapping_wrong_parameter_types
would be more precise.
if ( | ||
jsonPath.isObject() && | ||
jsonPath.get("context", "").isString() && | ||
jsonPath.get("prefix", "").isString() && | ||
jsonPath.get("target", "").isString() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing a validation that target
is not empty. solc won't accept remappings with an empty target on the CLI.
self.expect_equal(len(diagnostics), 0, "no diagnostics") | ||
|
||
report = self.expect_report(published_diagnostics, f"{self.project_root_uri}/other-include-dir/otherlib/otherlib.sol") | ||
diagnostics = report['diagnostics'] | ||
self.expect_equal(len(diagnostics), 1, "no diagnostics") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that one of these "no diagnostics"
messages does not match the number :)
) | ||
|
||
# test file | ||
file_with_remapped_import_uri = 'file:///remapped-include.sol' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be best to set this to something that would match the remapping if used in an import to show that these URIs are not remapped.
Does this fix #12603? If so, please add Also needs rebase on latest |
73c097e
to
fed02e3
Compare
Rebased and resolved conflicts, should be in a more workable state now. |
support remappings in the lsp server by allowing reading the required configuration during lsp "initialize". the format expected is: ``` { "remappings": [{context: "", prefix: "foo", target: "bar"}] } ```
fed02e3
to
5cfb4b4
Compare
remappings.emplace_back(ImportRemapper::Remapping{ | ||
jsonPath.get("context", "").asString(), | ||
jsonPath.get("prefix", "").asString(), | ||
jsonPath.get("target", "").asString(), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remappings.emplace_back(ImportRemapper::Remapping{ | |
jsonPath.get("context", "").asString(), | |
jsonPath.get("prefix", "").asString(), | |
jsonPath.get("target", "").asString(), | |
}); | |
remappings.emplace_back( | |
jsonPath.get("context", "").asString(), | |
jsonPath.get("prefix", "").asString(), | |
jsonPath.get("target", "").asString(), | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, these get
s can also be replaced with getOrDefault<string>(jsonPath["prefix"], "")
.
{ | ||
if ( | ||
jsonPath.isObject() && | ||
jsonPath.get("context", "").isString() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New type checking helpers were added and recently merged in this pull request, so these should be changed to use isOfType<T>
or isOfTypeIfExists<T>
, whichever one is more appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd hold off a bit with using these helpers everywhere. I wanted to get them merged not to stall the asm import PR but in the end we may and up removing them (#13579 (comment)). Depends on what we end up with after #13579. I mean, it's fine to use them but for now I'd also not force that.
|
||
if (typeFailures) | ||
m_client.trace("Invalid JSON configuration passed. \"remappings\" should be of form [{\"context\":\"\", \"prefix\":\"foo\", \"target\":\"bar\"}]."); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, we're choosing to close this PR as we won't allocate any time to this particular area. |
What
enables client's of the lsp server to configure remappings during the initialisation command.
we already allow configuring import-paths through the initialisation, so hopefully this is not controversial.
the format expected to be passed in from the initialise json is:
Why
Because without being able to set remappings, the lsp-server throws errors for any project that requires them.
Related