Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

chrisfarms
Copy link

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:

{ 
  "remappings": [
      {context: "", prefix: "foo", target: "bar"},
      ...
  ]
}

Why

Because without being able to set remappings, the lsp-server throws errors for any project that requires them.

Related

@christianparpart
Copy link
Member

Many thanks for your contribution @chrisfarms. We will take a close look at your work. :)

Copy link
Member

@christianparpart christianparpart left a 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. :)

@chrisfarms
Copy link
Author

Thanks, addressed your review comments.

Will take a look at the lsp.py tests shortly (had not spotted those tests) 👍

@chrisfarms
Copy link
Author

added a very basic case to the python lsp tests

@chrisfarms chrisfarms force-pushed the lsp-remappings branch 2 times, most recently from 309477c to 193d3b8 Compare August 25, 2022 07:35
@Marenz
Copy link
Contributor

Marenz commented Aug 29, 2022

I rebased the PR to the latest develop branch to fix the pylint CI failure

Marenz
Marenz previously approved these changes Aug 29, 2022
@Marenz Marenz enabled auto-merge August 29, 2022 12:48
@Marenz Marenz disabled auto-merge August 29, 2022 12:56
@christianparpart
Copy link
Member

christianparpart commented Sep 5, 2022

@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.

Marenz
Marenz previously approved these changes Sep 5, 2022
@chrisfarms
Copy link
Author

@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!

Copy link
Member

@leonardoalt leonardoalt left a comment

Choose a reason for hiding this comment

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

Need some clarification

@cameel cameel added the selected for development It's on our short-term development label Sep 8, 2022
@cameel cameel removed the selected for development It's on our short-term development label Sep 8, 2022
@Marenz Marenz force-pushed the lsp-remappings branch 2 times, most recently from d0b55ec to 73c097e Compare September 13, 2022 13:19
@christianparpart
Copy link
Member

Adding @cameel for the final review.

Copy link
Member

@cameel cameel left a 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.

Comment on lines +225 to +232
if (
jsonPath.isObject() &&
jsonPath.get("context", "").isString() &&
jsonPath.get("prefix", "").isString() &&
jsonPath.get("target", "").isString()
)
Copy link
Member

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:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Comment on lines +225 to +232
if (
jsonPath.isObject() &&
jsonPath.get("context", "").isString() &&
jsonPath.get("prefix", "").isString() &&
jsonPath.get("target", "").isString()
)
Copy link
Member

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.

Comment on lines +1601 to +1605
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")
Copy link
Member

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'
Copy link
Member

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.

@cameel
Copy link
Member

cameel commented Oct 21, 2022

Does this fix #12603? If so, please add #Fixes #12603 in the PR description.

Also needs rebase on latest develop and approvals from @christianparpart and @leonardoalt.

@nikola-matic
Copy link
Collaborator

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"}] }
```
Comment on lines +233 to +237
remappings.emplace_back(ImportRemapper::Remapping{
jsonPath.get("context", "").asString(),
jsonPath.get("prefix", "").asString(),
jsonPath.get("target", "").asString(),
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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(),
);

Copy link
Collaborator

Choose a reason for hiding this comment

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

By the way, these gets can also be replaced with getOrDefault<string>(jsonPath["prefix"], "").

{
if (
jsonPath.isObject() &&
jsonPath.get("context", "").isString() &&
Copy link
Collaborator

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.

Copy link
Member

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\"}].");

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

@NunoFilipeSantos
Copy link
Contributor

Right now, we're choosing to close this PR as we won't allocate any time to this particular area.

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

Successfully merging this pull request may close these issues.

7 participants