Giter VIP home page Giter VIP logo

fmt-micro's People

Contributors

sum01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fmt-micro's Issues

Support for "unsupported" filetypes

I'm adding support for files that Micro doesn't seem to support (when doing CurView().Buf:FileType()). It already mostly works, but I want to add shebang support to detect shell/bash files without extensions. Turns out Micro can detect shebangs (but only on-load, not on-save), so I guess I don't need to do that.

This will allow for shfmt and prettier to work on some undetected filetypes, along with anything else that gets added later.

I guess it could optionally be used 100% of the time, and then the literal file extension could be used in insert() when adding formatters, but I'm unsure if that's pointless or not.

Use Luacheck recommendations

Apply recommended luacheck stuff. Basically everything to local, both functions and vars.

It seems that MakeCommand requires a non-local function, so I can't use all recommendations

settings very noisy

fmt version:

3.1.1

Expected behavior:

only used languages appear in the config

Actual behavior:

all languages appear/ most of them like "fortran-formatter": "", which is quite disturbing

I hope this is either a user error or relatively inexpensive to fix.

Get JobSpawn working

Micro's JobSpawn is the only portable way to run OS commands, since the Go lib os/exec isn't available from the plugin bindings.

JobStart can't shouldn't be used, since it is just a shortcut to run shell commands, which aren't compatible with systems that don't have sh.

I've tried implementing JobSpawn in various ways, but it always outputs errors instead of running. Needs more work...

All I know is that it should look something like JobSpawn(target_fmt[2], {args, file}, "", "", "fmt.onExit") but I've tried this with both Luafmt & Prettier, and both complain of invalid args.

Get formatter on save/run

Instead of keeping a list of formatters in a var at all times, I think it'd be better to get them when format() runs instead. Then the fmt update and saved_settings things can be removed, as can the global var.

Note to self: Check DirectoryName(CurView().Buf.AbsPath) for an uncrustify .cfg before the WorkingDirectory(), if they differ.

Add C/C++/C#/ObjectiveC/D/Java/Pawn/VALA support

Most likely by using Uncrustify.

Alternative: Astyle (but it supports less languages)

Edit

Uncrustify might cause me some issues, as it seemingly requires a config file, along with both an input & output file.

While I can think of a rather easy way to get around supply the path twice to the command, I don't think I want to write up a file finder just for Uncrustify's config file.

But maybe I'm overlooking some command..

Optional user-defined args

Have a way for the user to override our default settings.


Problem

User wants different args to run on prettier, but only with Javascript.

Solution

User adds

"fmt|js": "prettier --write"

to settings.json, which we check for before using our built-in defaults.

Considerations

Positives

  • The user can even define an unsupported formatter, and it should still work.

Negatives

  • I don't see an easy way to use the custom settings with all of its filetypes, at least not without duplicating the setting and changing the language.
  • The user must know the filetype that Micro actually detects (ex: js for Javascript), and if it's an Unknown type, they must also know to put the file extension, such as p for Pawn.

Use display names

Have a display name for both the default formatters, and known languages, so a more "common" name can be used.

So instead of tex-formatter in settings, it would be latex-formatter, or pawn-formatter instead of p-formatter. And for any formatters with weird cli commands, we "obfuscate" and allow for the display name to be used in settings.json.

This also prevents problems with regressions if/when Micro suddenly "learns" about a new language. What I mean is that, if Micro suddenly recognized Pawn then it would break the p-formater setting. By using display names, we avoid that.

The only issue is that means we'll have to keep a language list.

Add more formatters in v2

Should probably use OOP

As it is now, the code is kind of hastily written, and could probably benefit from OOP.

Each insert() could be changed to something like

fmt_list[#fmt_list + 1] = formatter:new(lang = {"css", "html", "javascript"}, cli = "js-beautify",  args = {"-r", "-f"})

which should cut down on all the looping it does.

At the same time, maybe a display_name could be added, so that the user can use that instead of the cli command as the name. This would help on some formatters that require odd cli calls, such as formatR with it's formatR::input() or whatever. However, that'd require moving to major version 3, as it changes the user interface.

Allow for duplicate supported file-types

Allow for duplicate file-types in fmt_table by not assigning the key like fmt_table["filetype"] = "value" but instead using table.insert(fmt_table, values). Reading the table will require nested loops, as doing this will mean we will have a potentially "table in a table in a table" as a worse-case scenario.

Reasoning: Some people might prefer one formatter over another, so this will allow conflicting formatters to exist in the same table, and also allow us to worry less over potential conflicts

Consider auto-editing the uncrustify cfg

There should be a way to update/edit the configs/uncrustify/defaults.cfg with settings from get_settings() so that the user doesn't need to actually replace the file to get the desired results.

To be honest, I'm clueless as to how to do edits to a file with Lua. I'm sure I'd be able to figure it out, but it might take a while. Also, considering how big the Uncrustify .cfg file is, it might take a lot of code to get working to the users settings.

Consider a "lang-pref" option

It should look for any languages that have more than 1 supported formatter, and create an option like

AddOption(lang .. "-pref", "none")

Then this can be checked before choosing the formatter. If it's "none" it will use the first found formatter, but if it's set to something like "css-pref": "csscomb" (in the settings.json) then it will use csscomb instead of prettier (or whatever).

This will allow for clashing formatters to be both enabled at the same time, but the user to preffer one formatter for a specific filetype.

Respect user settings (when possible)

Grab the users settings (tabs/space, indent size, etc.), and apply it via formatter args (if they support it).

This should not interfere with the editorconfig plugin.

Notes

  • rustfmt reads from a rustfmt.toml config file, can't directly pass options.
  • prettier can read from a config, but also supports args. Unsure if there'll be a clash.
  • luafmt only supports tab-size, nothing else.
  • gofmt only accepts tabs
  • rubocop seems to lack any relevant args.
  • fish_indent seems to lack any relevant args.
  • crystal seems to lack any relevant args.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.