Skip to content

Cleanup extension #106

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

Merged
merged 11 commits into from
Apr 8, 2025
Merged

Conversation

milesziemer
Copy link
Contributor

This PR includes a number of various cleanups and additions.

  • Added a config option to specify an executable to run the language server. If not provided, fallback to coursier.
  • Removed an unnecessary formatting provider the extension was setting up. VSCode will automatically set it up
    if the language server advertises the capability, which it does.
  • Refactored and cleaned up the implementations of smithy/jarFileContents and smithy/selectorCommand.
  • Refactored and cleaned up the client/server options the extension sets up. We don't need to figure out what the
    root directory is, or send it to the language server, since vscode and the language server will infer it. I also
    removed the rootPath config option for the same reasons. We also set up a client-side file system watcher, which
    is unnecessary since the server will dynamically register it.
  • Refactored and cleaned up coursier setup. We were creating a local tcp server that acted as a proxy to the language
    server running in a separate process which we ran manually. This is unnecessary because the vscode extension API
    allows you to provide a command + args that it will use to run the language server. This at the very least improves
    startup time.
  • Cleaned up the naming of extension config options, and how the extension retrieves them. I added config options
    for each existing option with the prefix smithy (or smithy.server where applicable), instead of the smithyLsp
    prefix. I kept the old options, but deprecated them, and removed their default values. The extension will now choose
    the old options when they've been specified, but defaults to the new options. In a following release, we will remove
    the old options.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@milesziemer
Copy link
Contributor Author

Draft until #105

Adds a config option to specify a specific command to run the language
server. When not set, the extension falls back to running with coursier.
By default, the config option is not set.

I need to clean up the config option a bit, since when you specify a
specific command, you can just use stdio, meaning the arguments passed
to the language server should just be "0". So really no args should be
set in the config option.
The language server tells vscode it provides a formatter through its
capabilities, so we don't need any client-side code.
Cleaned up the implementations and organization of the
smithy/jarFileContents and smithy/selectorCommand lsp extension
handlers.
Refactored language client options and server config sent on
initialization, and removed unnecessary config.

We had some logic to figure out the root directory and workspace folder
which was used to refine which files the extension should care about,
but I think this is now unnecessary because the language server will
just find project roots anyway. There was also an extension config
option to set the root path, which should be unnecessary for the same
reason, so I removed it. The client still sends the workspace folder and
root path in the initialize request, so we aren't losing any information
here.

I also removed the file system watcher, as the server will dynamically
register that.
Two things:

Some refactoring to use execFile instead of spawn for checking if
coursier is available, which is more lightweight.

Changed the way the server is run with coursier to have vscode run the
coursier command directly. Previously, we created a local tcp server
that acted as a proxy for the language server, which we ran in a
separate process. But I don't think this extra layer of indirection is
necessary, since vscode's lsp api can be given a command and some args
to use to start the server.
Changed the prefix of config properties from `smithyLsp` to just
`smithy` (or `smithy.server`, where applicable). I kept the existing
config properties, but added a deprecation message to them, pointing to
the new property. We will keep these in the next release, but remove
them in the following release.

Small note about the `smithy.server.version` property: I didn't give it
a default value, since that would have been chosen over a user-defined
version in the old property. When we remove the old properties, we can
add the default to the new one.

I also added a simple api for getting config settings in the extension,
that prefers the new properties over the old.
In a previous commit, I changed the server initializationOptions to have
a nested `diagnostics` object. That isn't what the server expects at the
moment, and it is probably more complicated than necessary to change, so
I changed it back.
For some reason, when a string config option isn't specified it gets a
default value of `""`, so when we checked the new config option, the
empty string value would get chosen instead. So I added a default of
null for the old options, and I also switched the existing defaults to
the new options, choosing the old options first if they're present.
Not sure why I removed it in the first place.
@milesziemer milesziemer marked this pull request as ready for review April 7, 2025 18:35
@milesziemer milesziemer requested a review from a team as a code owner April 7, 2025 18:35
@milesziemer milesziemer requested review from JordonPhillips and joewyz and removed request for JordonPhillips April 7, 2025 18:35
@milesziemer milesziemer merged commit d53db95 into smithy-lang:main Apr 8, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants