-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add swift language #2033
Add swift language #2033
Conversation
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 looking good, just a few scopes need adjustment
w.r.t. the lsp, I've seen similar behavior from erlang-ls, it will auto-complete arguments as well, so maps:get| %% hit tab when cursor is on |
%% becomes
maps:get(Arg1, Arg2)| I haven't dug into it further but I think it's behavior on the language server side. Maybe those language servers implement an outdated version of the spec. |
oh, also please run |
thanks, updated the PR, and that makes sense. I'm going to try to look into that issue further, but it auto completes significantly more (even inlines the parameter name) which I haven't seen other LSP's do |
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.
nice work, thanks!
@Dispersia for erlang-ls this issue has some discussion on it: erlang-ls/erlang_ls#772. From the discussion there it sounds like there's a "snippets" approach to doing autocomplete. I'll dig into this more but that might be a good hint for swift as well. |
Also would you mind adding a quick note to the new lsp wiki for sourcekit-lsp? https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers |
Added to the wiki, and appreciate the link, that will definitely help! |
Finally understand why it does this. I don't know if helix supports snippets (or if it's a standardized thing, or it's a vscode thing), but what happens is in sourcekit-lsp they do this: Text returned from sourcekitd comes in as something such as I don't know if this is something that's want to be supported (trying to find if that's specific to vscode or it's part of an actual spec), but going to make the recommendation to remove all of it if snippets aren't supported to sourcekit-lsp's working group Also created a post on their forums to see what they think about deleting everything besides the method if snippet is passed as false: https://forums.swift.org/t/additions-to-codecompletion/56649 |
Ah makes sense! That's what I found with the Erlang LS as well (erlang-ls/erlang_ls#1263). There's a PR for snippets support in helix (#1178) but it seems like a pretty complicated feature and the PR appears to have paused. IMO language servers should not auto-complete past the function name - not even the parens because that would mess up auto-pairs - because you have to edit backwards to deal with the generated stuff. Plus it kinda bumps with signature help (#1755) |
Funny they both do the same thing, and we both came to the same conclusion of what should actually happen haha. Will wait to see their response, hopefully they agree 😄 EDIT: I just re-read your first response to the issue, I somehow completely missed that you had already stated it might have been due to snippets lol. /facepalm |
Nice to see Swift supported (Xcode is horrible). However, the syntax highlighting is only partially functional. Types are only highlighted when they're used as type annotations, which is not how Swift is conventionally highlighted (in Xcode, at least, which uses the same logic). Take the following example:
The annotation (the In the following example,
On the other hand, the type (
So, it's not even consistent. The The I use minimal highlighting, so am not sure what else is missing, but noticed that enums do not reflect the style bound to |
This is two years old, have you tried updating the comment and changing the config? I'm sure it supports all of the new syntax and has a lot of improvements, it looks fairly active and gets updated weekly (I haven't used swift since shortly after I added this) so I haven't had the need to update it |
Updating which comment? Changing which config? I'm using the Swift support that is included with Helix (with SourceKit LSP). I'm not sure what else I'm meant to use?? What gets updated weekly? Swift support?? It's not very mature, if that's the case. If you're not using it, I guess it's not your problem anymore. I appreciate you taking the time to reply still. All the best. |
Sorry my phone changed "commit" to "comment", but the grammars get updated weekly (which is everything from highlighting to when you hit enter how many spaces should be there, etc, which is supplied by tree-sitter): you can see the current version helix is using is like a year and a half old: Line 1733 in 5c567f3
If you want to try, its fairly simple to update these grammars, copy over their queries/{highlights|indents|locals|textobjects}.scm folder into the helixs queries/swift subfolder, update that commit id i linked in languages.toml, and then update the grammars like shown under https://docs.helix-editor.com/guides/index.html (it's just changing from like @Property to @function.property, and things like that) should be fairly simple to open a PR for it if you're interesting in updating the grammars, and if you run into any issues feel free make an issue and we can discuss it |
Thank you, @Dispersia. I see. I can't commit to doing it right now, but I am keen to improve Swift support, and to begin contributing to Helix. I don't know Rust, but could help with the Swift grammar etc.
Will do. Thanks again. All the best. |
I'm just looking into this a bit more. I think I get most of it, but am unsure on what to commit to (to get the updated ID). I installed Helix with I can reinstall Helix manually, and build it from source, but even then, I'm not sure if I'm supposed to commit to Helix or to a Swift-specific repo (after I update the I'd appreciate any guidance. Thanks again. |
the updated id is just whatever the latest commit on their branch is, so https://github.com/alex-pinkus/tree-sitter-swift latest (as of me posting this message) is 1c586339fb00014b23d6933f2cc32b588a226f3b you'll be commiting to helix, with changes to this directory: https://github.com/helix-editor/helix/tree/master/runtime/queries/swift with changes from theirs for the files i had listed above and ya, you will need to build it locally, as you will need to update the languages.toml, which is built into the executable (but you wont touch any rust code, just configurations) |
Thank you, @Dispersia. Much appreciated. I'll give it a go. |
Sorry to be a pain. I'm a bit stuck. I cloned TreeSitter and Helix, set I then edited When I tried to rebuild Helix (using
Sorry to keep bothering you @Dispersia. Is there somewhere better I can ask for help with this? Thanks again. |
I'll open a new issue, @Dispersia. It's not really fair to expect you to onboard me (no good deed goes unpunished, ay). Best wishes. Thanks again. You've been awesome. |
#1964
Was also planning on using this, so went ahead and implemented it. From that issue, I forked the current tree-sitter-swift and checked in the current build configs, until a better solution is implemented (if we just want to wait if they want to add a separate branch, that's fine too).
There are a few keywords that are in the highlights.scm that I didn't see in https://docs.helix-editor.com/themes.html#syntax-highlighting, so I didn't know how to handle them and just left them as is.
Finally, there is one issue in swift I can't seem to figure out.
when tabbing through, it's auto appending the parenthesis, but puts the cursor outside so you have to backspace. Is there a way to prevent this I didn't see?