zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.77k stars 3.06k forks source link

Add a `current buffer language` variable in task #12628

Open failable opened 5 months ago

failable commented 5 months ago

Check for existing issues

Describe the feature

Add a current buffer language variable in task.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

osiewicz commented 5 months ago

At glance this sounds reasonable, but what use case do you have for this?

failable commented 5 months ago

Hello, I came up with this when I defining a task "post current file content to dpaste" and notice there is a param to set the syntax highlight, though some transformation like lowering case must be done to make the API. There are also some tools like rg accept language / file type liked params.

baldwindavid commented 5 months ago

I have a use case to slightly improve a hacky workaround for Rewrap-ish (https://marketplace.visualstudio.com/items?itemName=stkb.rewrap) behavior for comments/docs.

I have this keymap that select the entire lines of an already visually selected comment, uncomments, copies, comments again, and then runs a task...

"#": [
  "workspace::SendKeystrokes",
  ": select line enter g c cmd-c g c : task:spawn enter Reflow Comments enter"
],

The task that's run is...

  {
    "label": "Reflow Comments",
    "command": "pbpaste | fmt -w 78 | pbcopy",
    "reveal": "never"
  },

This task takes the copied comment, formats it to 78 characters, and copies to the clipboard. I can then press p to replace the currently selected content with the reformatted content.

The main issue for this use case is that I'm hard-coding 78 characters in. My main language is elixir which has two character comments (#) so it is formatting to 80 characters accounting for those two. Having access to the current language could at least allow for choosing the appropriate amount of characters based upon the language.

As an aside, the task:spawn Reflow Comments enter dance seems to have broken in keymaps so the whole thing stopped working.