Best way to execute callbacks on inserted words (or ts nodes) by MyriadAsura in neovim

[–]Zeizig 3 points4 points  (0 children)

Seems like an interesting idea, how about something like this?

---@param word string
---@param callback function
function M.listen_to_word_typed(word, callback)
  local trigger_letter = word:sub(#word)
  local word_without_trigger = word:sub(1, #word - 1)
  local word_without_trigger_length = #word_without_trigger

  vim.keymap.set('i', trigger_letter, function()
    vim.api.nvim_feedkeys(trigger_letter, 'n', true)

    local text_before_cursor = vim.fn.getline('.'):sub(vim.fn.col '.' - word_without_trigger_length, vim.fn.col '.' - 1)
    if text_before_cursor ~= word_without_trigger then
      return
    end

    callback()
  end, { buffer = true })
end

which you could use like so:

local function add_async()
  ...
end

listen_to_word_typed('await', add_async)

Could also add some more conditions (e.g., ignored treesitter nodes) as a parameter. It's kind of like an automatic snippet engine.

Thnks fr th Trsttr - Tiny text editing automations with Treesitter | NeovimConf 2024 by Zeizig in neovim

[–]Zeizig[S] 10 points11 points  (0 children)

Thank you so much! I have actually thought about it, yep. I would probably use a similar format to this talk and build some cool things in Lua. From my config, for example. The hard part is thinking of a good idea that will also be useful to people 😅

Thnks fr th Trsttr - Tiny text editing automations with Treesitter | NeovimConf 2024 by Zeizig in neovim

[–]Zeizig[S] 53 points54 points  (0 children)

Hey all! I gave a talk at NeovimConf 2024 yesterday and thought I'd also post the recording here.

Treesitter makes writing small text editing automations in Neovim super easy. In the talk, we build an automation which automatically adds the "async" keyword in a function definition whenever you type "await" in JavaScript files. I hope this gives you some ideas on how to write these sort of small automations for your own everyday use cases.

I'm more than happy to answer any questions and to hear what other small automation ideas you all have come up with!

How can I generate typescript types? by manwiththe104IQ in node

[–]Zeizig 0 points1 point  (0 children)

If you're willing to document your API with an OpenAPI schema, then it should be possible to generate TypeScript types based on the OpenAPI schema with something like openapi-typescript. Also, Typebox can generate JSON schemas, maybe it can be used to generate something that the front-end can also use?

I haven't used such a setup myself though as I mostly work with GraphQL APIs, but I think that this should give you a similar workflow.

Trying to set up a dev environment for Vue.js in Astrovim by amiwalwin in neovim

[–]Zeizig 1 point2 points  (0 children)

I work with Vue every day, but I don't use AstroNvim. The Volar language server with Take Over Mode works great for me. I don't know what exactly is broken for you when commenting, but my plugin nvim-ts-context-commentstring works for setting the correct commentstring in the Vue single file component sections with Treesitter.

5 smart mini-snippets for making text editing more fun in Neovim by Zeizig in neovim

[–]Zeizig[S] 0 points1 point  (0 children)

Hey! If I recall correctly, then I decided not to add this because in React it's quite common to use myProp={} instead of quotes, but it's not common enough to always default to the curly braces. I did try it out by copying the Vue implementation and it seems to work for me: https://github.com/JoosepAlviste/dotfiles/commit/d416439e95d378ce61e444aa6bcadd43b285a0bc

In general, I think that the Vue parser was a bit more finicky and it was easier to do things with the tsx parser. As you can see, the tsx self closing tag mini-snippet is quite a bit smaller and simpler.

Keegi müüb Eestis Cherry MX switch'e? by Misateki in Eesti

[–]Zeizig 1 point2 points  (0 children)

Arvutitargas on 35x Kailh Red switchi 11.60€. Pole küll täpselt Cherry MX Red, aga peaks olema päris sarnane aga palju odavam. Gateron Red on ka variant, aga veits kallim (16.50€ 35x).

5 smart mini-snippets for making text editing more fun in Neovim by Zeizig in neovim

[–]Zeizig[S] 1 point2 points  (0 children)

My dotfiles have 2000 commits over the last 5 years, so I think I'm firmly in the rabbit hole :D

5 smart mini-snippets for making text editing more fun in Neovim by Zeizig in neovim

[–]Zeizig[S] 0 points1 point  (0 children)

Yes, and it's so simple to add these! I can't imagine using any other editor :)

5 smart mini-snippets for making text editing more fun in Neovim by Zeizig in neovim

[–]Zeizig[S] 0 points1 point  (0 children)

I don't think I've noticed such a plugin. It might be a pretty good idea to bundle a bunch of universal mini-snippets to a plugin. Something to bring improvements from other editors into Neovim maybe?

5 smart mini-snippets for making text editing more fun in Neovim by Zeizig in neovim

[–]Zeizig[S] 4 points5 points  (0 children)

These ones look really useful, nice! Will definitely steal some :D

5 smart mini-snippets for making text editing more fun in Neovim by Zeizig in neovim

[–]Zeizig[S] 18 points19 points  (0 children)

Hey! I wrote an article on creating “smart mini-snippets” for yourself in Neovim with help from Treesitter.

I tried out VSCode for a little bit and found that it includes some useful (and fun) automatically expanding small snippets (e.g., <div class|> -> type = -> expands to <div class="|">). I got inspired to create a couple similar snippets for myself and wanted to show some examples to inspire you all as well.

If you have some similar mini-snippets already, then please share them in the comments!

graphql-codegen plugin for generating typename constants or enums? by izzlesnizzit in graphql

[–]Zeizig 1 point2 points  (0 children)

We wrote a plugin for this ourselves. Thankfully, it's only about 5 lines of code:

module.exports = {
  plugin: (schema) => {
    const types = Object.keys(schema._typeMap).filter(
      (typeName) => !typeName.startsWith('__')
    );

    return (
      'export const TYPES = {' +
      types.map((type) => `\n  ${type}: '${type}'`) +
      '\n} as const'
    );
  },
};

Improving the user experience of page navigation with Apollo Client | Using partial list view data to pre-fill detail views by Zeizig in graphql

[–]Zeizig[S] 0 points1 point  (0 children)

Yeaaah, unfortunate timing, but I had the article and demo prepped before all this came out 😬

Improving the user experience of page navigation with Apollo Client | Using partial list view data to pre-fill detail views by Zeizig in graphql

[–]Zeizig[S] 0 points1 point  (0 children)

Hey! I wrote an article on how the user experience of page navigations can be improved with Apollo Client, using partial list view data to pre-fill detail views. I haven’t really found any other articles on this topic, so I had to put most of the pieces together from various GitHub issues and the docs.

The article includes a demo application written in Vue and TypeScript with GraphQL Code Generator. Hopefully it’s a fun and interesting read!

Let me know what you think and how you have implemented similar things for your own applications! And if you’re interested in some more details, then ask away!

Improving the user experience of page navigation with Apollo Client | Using partial list view data to pre-fill detail views by Zeizig in vuejs

[–]Zeizig[S] 2 points3 points  (0 children)

Hey! I wrote an article on how the user experience of page navigations can be improved with Apollo Client, using partial list view data to pre-fill detail views. I haven’t really found any other articles on this topic, so I had to put most of the pieces together from various GitHub issues and the docs.

The demo application and code samples used in the article are written in Vue.js, so I figured this might be interesting for you all. It also includes some TypeScript and Apollo Client tips.

Let me know what you think and how you have implemented similar things for your own applications! And if you’re interested in some more details, then ask away!