Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

perf: modularize built-ins #288

Merged
merged 7 commits into from
Nov 8, 2021
Merged

perf: modularize built-ins #288

merged 7 commits into from
Nov 8, 2021

Conversation

jose-elias-alvarez
Copy link
Owner

@jose-elias-alvarez jose-elias-alvarez commented Oct 27, 2021

The library of built-ins has grown beyond what I imagined. Currently, built-ins are modularized by method, which means that requiring and registering a single built-in runs helpers.make_builtin once for every other built-in for the same method. The performance impact isn't huge, but it'll naturally grow bigger as more built-ins are added, and working with built-in files is also becoming tedious.

This PR lays out a simple structure to completely modularize built-ins using metatables. Finishing this will require a couple of hours of copy-pasting but shouldn't be too difficult.

  • Formatting
  • Diagnostics
  • Code actions
  • Hover
  • Completion
  • Update documentation

@jose-elias-alvarez jose-elias-alvarez marked this pull request as draft October 28, 2021 03:04
@jose-elias-alvarez jose-elias-alvarez changed the title [WIP] perf: modularize built-ins perf: modularize built-ins Oct 28, 2021
@jose-elias-alvarez jose-elias-alvarez marked this pull request as ready for review November 8, 2021 21:56
@jose-elias-alvarez jose-elias-alvarez merged commit 5005297 into main Nov 8, 2021
@@ -1018,7 +1039,7 @@ local sources = { null_ls.builtins.formatting.shfmt }

##### Defaults

- `filetypes = { "sh" }`
- `filetypes = { "sh", "zsh" }`
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if shfmt supports zsh actually.
mvdan/sh#120

Copy link
Owner Author

Choose a reason for hiding this comment

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

That's strange – I've been using shfmt for zsh since we added it about 2 weeks ago and haven't run into any problems. I don't know much about the project, but maybe the issue you linked is about a different feature?

Copy link
Contributor

@gegoune gegoune Nov 8, 2021

Choose a reason for hiding this comment

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

Hmm, not so sure, I just tried it myself for the first time and it reformatted:

if (( $+commands[ls] )); then

to

if (($ + commands[ls])); then

which is not valid and errors with bad math expression. There is no mention of official support for zsh in shfmt's repository, so I would recommend not setting it as default option here.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Got it – I'll remove it from the defaults.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, amazing refactor btw, excellent work on null-ls, using it every day!

@jose-elias-alvarez jose-elias-alvarez deleted the modularize-builtins branch November 8, 2021 22:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants