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

Tact highlight and grammar support for the VIM editor #320

Closed
reveloper opened this issue Sep 25, 2023 · 33 comments · Fixed by #348
Closed

Tact highlight and grammar support for the VIM editor #320

reveloper opened this issue Sep 25, 2023 · 33 comments · Fixed by #348
Assignees
Labels
Approved This proposal is approved by the committee Developer Tool Related to tools or utilities used by developers

Comments

@reveloper
Copy link
Contributor

reveloper commented Sep 25, 2023

Summary

Adding support for Tact programming language syntax highlighting in the VIM editor.

ton-bounty created with @footsteps_helper_bot

Context

The Tact programming language is widely used for high-level smart contract development in TON.

However, currently, there is no built-in syntax highlighting support for Tact in the VIM code editor. This project aims to address this issue by creating a plugin or extension that enables Tact syntax highlighting with grammar support in VIM.

VIM highlight and grammar extension for the Tact should be implemented with support in the vim-plug.

References

Alternative highlights for Tact:

Estimate suggested reward

1500$ in TON

@reveloper reveloper added the Developer Tool Related to tools or utilities used by developers label Sep 25, 2023
@liketurbo
Copy link
Contributor

liketurbo commented Sep 25, 2023

Can it be extended it to Vim/Neovim? ... Although Neovim support requires a tree-sitter implementation from #302

@novusnota
Copy link
Contributor

novusnota commented Sep 25, 2023

@liketurbo Both Vim/Neovim can use regular expression-based grammars, but only Neovim has a valid option to use tree-sitter. So, it's probably better to just implement the latter, as it would also enable: GitHub-wise highlighting, other editors (I often use helix, for example).

But if needed, I can do one specifically for Vim.

@reveloper
Copy link
Contributor Author

@liketurbo I'm not sure, I'll try to figure out what is required in the community. In general, I prefer to do this in separate ton-bonties.

@reveloper
Copy link
Contributor Author

It seems that we can add support to Neovim too(with a separate ton bounty).
I would ask in this ton-bounty implement support only for the Vim.

@novusnota
Copy link
Contributor

@reveloper Great. The Vim-specific implementation was in the private works of mine for a long time and it's near completed. Probably would take me a day or two to polish & publish it. Brb :)

@zenixls2
Copy link

Still modifying...
https://github.com/zenixls2/vim-tact
in case this is not approved, vim users could still get some kind of highlights on it.
This one doesn't 100% follow the vscode json.

@reveloper
Copy link
Contributor Author

reveloper commented Sep 27, 2023

@novusnota Woah! What about grammar support, could you also implement this for Tact in VIM?

@novusnota
Copy link
Contributor

novusnota commented Sep 27, 2023

@reveloper Do you mean autocomplete support? If so, then yes. And I'm aiming for full-coverage of grammar.ohm of Tact (essentially, it's actual formal specification), just like I did with the Prism.js grammars before.

Needs about a day of work, the incomplete (and a bit broken at times) example of @zenixls2 really motivates to make mine even better :)

@zenixls2
Copy link

Actually i made some references to both rust.vim and vim-solidity.
They have made some amazing work on supporting their syntaxes

@reveloper reveloper changed the title Tact highlight support for the VIM editor Tact highlight and grammar support for the VIM editor Sep 27, 2023
@delovoyhomie
Copy link
Collaborator

@reveloper, I like your idea on add grammar support in addition to highlighting. After having a private conversation with you, $1500 seems totally acceptable, considering the complexity and the amount of work involved.

You can be present during the execution. Please leave your repository where the progress will be tracked.

@delovoyhomie delovoyhomie added the Approved This proposal is approved by the committee label Sep 28, 2023
@zenixls2
Copy link

If there's anything i could alsp help please let me know. I really need a strong plugin for tact.

@novusnota
Copy link
Contributor

novusnota commented Sep 28, 2023

A little preview of what's coming, expect minor changes depending on custom color schemes (One Dark is on the screenshot below). Finishing omnicompletion, compiler and indentation support tomorrow. Also, working on one extra feature, which would help everyone working with Tact, including users of my Vim plugin 🤗

@novusnota
Copy link
Contributor

novusnota commented Oct 3, 2023

I've been extensively working on grammar support and plenty of other helpful features to present my plugin for Tact challengers. As tasks were planned to be revealed today, I'm planning to deliver final results today too. Stay tuned :)

UPD: It had its own challenges, but I'm working to deliver it very soon!

@novusnota
Copy link
Contributor

novusnota commented Oct 13, 2023

The biggest file in the whole plugin is tightly packed with grammar & context recognition for intelligent completion and even basic linting. I did a lot of rather convoluted RegExp work to make this happen, and it's at times smarter than the Language Server built in the official Tact plugin for VSCode :)

image

I really want Tact users to be productive when using my plugin, hence I'm testing all the corner-cases (and, sometimes, adding small quality of life features).

UPD: Sorry for the big delay in my work, trying to finish this soon 🙏

@reveloper
Copy link
Contributor Author

@novusnota This sounds awesome! We are looking forward to the release!

@novusnota
Copy link
Contributor

novusnota commented Oct 27, 2023

@reveloper @delovoyhomie 🚀 Done! Whew, that took some time, apologies for the delays!

Here's a screencast of creating a simple counter contract from the ground-up using my plugin:

Note, that this shows only a fraction of possible configuration, completion and other options. Moreover, if I were to type this example with incorrect syntax that would've been detected by the basic linting capabilities, which are built in the completion as well 🔥

Link to the well-documented plugin repository: tact.vim
Name for the Hall of Fame: Novus Nota
TON wallet address for reward: UQDew1rvHuMmMkmxG_fQahGymzIOF2_9TpgLftMUuxpKLBIr
TON wallet address in older, EQ format (just in case): EQDew1rvHuMmMkmxG_fQahGymzIOF2_9TpgLftMUuxpKLE_u

P.S.: @zenixls2 here you go, a very strong plugin 👍

@reveloper
Copy link
Contributor Author

reveloper commented Oct 30, 2023

@novusnota, This looks fantastic, thank you for this great job!

I have a few questions as an afterword:

  • Can we arrange how to support this plugin for new updates of Tact?
  • If this is possible, publishing this plugin in the Tact organization would be great.

@novusnota
Copy link
Contributor

@reveloper @delovoyhomie

The code throughout all the pars of the plugin is (IMHO):

  1. Very self-descriptive
  2. Well-commented

Let's take a look at the syntax/tact.vim file for example:

That said, I think that I'll simply continue maintaining this plugin for new Tact updates as I know the codebase of my plugin already :)

About moving it to tact-lang organization — sure thing, do I need to initiate the transfer? I'd like to retain my access to the repo from within the Tact organization to be able to maintain it :)

@anton-trunov
Copy link

@novusnota Awesome work! Could you please provide a minimal .vimrc file to assess the plugin for a non-Vim user (I only use Vim-bindings these days)? Would be great to see syntax highlighting, auto-indentation and try out code and abbreviations auto-completion as shown in the demo.

@novusnota
Copy link
Contributor

novusnota commented Oct 30, 2023

@anton-trunov Sure! Assuming you don't have any configuration in the .vimrc, you'll have to setup some saner defaults first before using my (or any other) plugin. Also, I won't introduce anything fancy and be using the built-in package management for Vim 8+.

Let's go:

  1. Get yourself a Vim of version 8+ installed and make sure to have git installed and present on your path as well
  2. Create a ~/.vimrc file (or ~/_vimrc if you're on Windows)
  3. Without such file there were sourced defaults by the Vim authors, but once it's created, we have to put them back explicitly by adding those lines in and saving changes :w:
unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim
  1. While we're here, let's add some tact.vim-specific stuff in as well. This time save and quit as we no longer need to add anything :wq:
let g:tact_style_guide = 1  " Enabling default indentation style

" the following is optional and added purely for your convenience:
inoremap <silent> <c-space> <c-x><c-o>  " Open completion menu on ctrl-space
  1. It's also nice to source in the extended defaults provided by the tpope/vim-sensible. To do so, let's use the built-in package manager:
On Windows, do this in PowerShell:
git clone 'https://github.com/tpope/vim-sensible.git' $HOME\vimfiles\pack\tpope\start\sensible

On Linux, macOS or *BSD:

git clone 'https://github.com/tpope/vim-sensible.git' '~/.vim/pack/tpope/start/sensible'
  1. Finally, let's install ⚡ tact.vim:
On Windows, do this in PowerShell:
git clone 'https://github.com/novusnota/tact.vim.git' $HOME\vimfiles\pack\novusnota\start\tact

On Linux, macOS or *BSD:

git clone 'https://github.com/novusnota/tact.vim.git' '~/.vim/pack/novusnota/start/tact'
  1. Start the Vim in the valid Tact project to be able to use :Tact command for easy compilation or simply provide any .tact file otherwise. Happy coding 🚀

@novusnota
Copy link
Contributor

novusnota commented Oct 30, 2023

P.S.: @reveloper @delovoyhomie Sent a PR to Hall of Fame as well :)

@anton-trunov
Copy link

@novusnota Thank you so much for such a detailed explanation (I think that deserves to be put into a wiki, or as a separate page into that repo, targeting beginners).

I could immediately see syntax highlighting, indentation works just fine for me. But auto-completion on <c-space> does not work on my machine. I'm using macOS with vim running inside the iterm2 terminal emulator. There is no other keyboard shortcut bound to Ctrl-Space.

When I type in foo: Int as uin and press Ctrl-Space, I get the following error message from Vim:

E29: No inserted text yet

I would expect to see a drop-down menu with all the unsigned integer types listed.

Any suggestions on how to fix it?

@anton-trunov
Copy link

But C-x C-o works. And I can expand abbreviations as well. This is some great work by you!

@novusnota
Copy link
Contributor

novusnota commented Oct 31, 2023

@anton-trunov Awesome, thanks 🤍

So, probably the only non-cross-platform thing about the plugin is the end-user keybindings. Therefore I only suggest, but not demand <c-space> for convenience :)

It turns out that on macOS CtrlSpace (^space) is used on the system level — to switch between keyboard layouts:

The simplest solution then is to disable or re-map it in the system settings to, say, CmdSpace.

But I came up with two alternatives as well, pick the one you prefer:

Using a different shortcut in Vim For example, `` in place of `` may work just fine as CmdSpace, but Vim is unpredictable when it comes to binding Cmd/Win keys, so that's kind of unreliable.

Alternatively, you may try one of the following instead of <c-space>:

  • <a-space>, which is a AltSpace press
  • <a-i>, which is a AltI press
  • <c-i>, which is a CtrlI press
Making iTerm2 pass the shortcut In similar fashion to how other GUI editors (like VSCode) deal with using CtrlSpace, you can try to intercept and override system keybindings in the current GUI app, and iTerm2 counts here too!

To make an iTerm2 "keyboard shortcut" specifically for CtrlSpace do:

  1. Enter the shortcut (^space)
  2. Select the action: «Send Text with "vim" Special Chars»
  3. Add the following as is to the final input field: \<C-space>

Here's how the UI of that process may look like:

P.S.: Sure, I'll consider adding those two guides somewhere — either in the README, Wiki or tact-docs even, if it's appropriate :)

@anton-trunov
Copy link

Everything looks ready from my side, the bounty can be fully paid. @novusnota could you please transfer the repo under the tact-lang org? We'll add you as a maintainer, of course.

@novusnota
Copy link
Contributor

@anton-trunov Yes, but first I need a permission to create new repositories there :)
image

@anton-trunov
Copy link

anton-trunov commented Oct 31, 2023

I just sent an invitation

@anton-trunov
Copy link

The transfer has been completed. Thanks a bunch!

@anton-trunov
Copy link

@novusnota Btw, is this plugin compatible with NeoVim?

@novusnota
Copy link
Contributor

novusnota commented Oct 31, 2023

@anton-trunov Yes it is! While main focus was on Vim, Neovim out-of-the box is compatible with the plugin 🎉

Oh, and Neovim enables sane defaults automatically, so there's no need in sourcing the default file or adding a tpope/vim-sensible plugin to it.

@anton-trunov
Copy link

Thank you. I added vim and neovim tags to the repo.

@novusnota
Copy link
Contributor

novusnota commented Nov 1, 2023

@delovoyhomie @reveloper According to the updated guidelines, submitted:

  1. Questbook proposal and a comment of it's completion.
  2. PR to this repository marking the completion of this DevTooling bounty.

P.S.: Forgot about the Questbook, now recovering. Only one proposal at a time is allowed to be made, so I'll submit a proposal for #302 right after this one gets resolved :)

@delovoyhomie
Copy link
Collaborator

Rewards sent!

Thank you for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved This proposal is approved by the committee Developer Tool Related to tools or utilities used by developers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants