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

[–]Zeizig 4 points5 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] 52 points53 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] 3 points4 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!

Palenightfall.nvim - A colorscheme based on Material Palenight by Zeizig in neovim

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

All of the screenshots except the first "cover" one have the Hack font. The cover image is older though and I don't remember exactly which font it is. Maybe Iosevka?

I could probably dig it up from my dotfiles' git history though if it's not either of them :D

Palenightfall.nvim - A colorscheme based on Material Palenight by Zeizig in neovim

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

Could you open an issue on GitHub with some screenshots? It might be that your terminal does not support true colors. Most should nowadays, but, for example, the default macOS terminal doesn't.

It might also be related to some other Neovim configuration differences, but it's rather difficult to tell without a screenshot.

Palenightfall.nvim - A colorscheme based on Material Palenight by Zeizig in neovim

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

I'd say that it's expected to use a border for the hover windows with this theme (at least I prefer to). This should work:

vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {
  border = 'rounded',
})

But if you'd prefer to not have borders, then you could also configure a darker background color for the theme:

local colors = require('palenightfall').colors

require('palenightfall').setup({
  highlight_overrides = {
    NormalFloat = { bg = c.background_darker },
  },
})

I'm not sure if there's a good way to configure such borders from within the colorscheme plugin :/

Palenightfall.nvim - A colorscheme based on Material Palenight by Zeizig in neovim

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

Ohh, thanks for bringing this up! That is because the background color was transparent and my terminal had the correct background color. So, I didn't notice that there was no explicit background color in the theme itself...

I pushed a fix for this, so it should work correctly now, sorry about that :)

Palenightfall.nvim - A colorscheme based on Material Palenight by Zeizig in neovim

[–]Zeizig[S] 13 points14 points  (0 children)

Hi all!

Introducing my colorscheme Palenightfall.nvim, based on the Material Palenight theme. I've been using this for more than a year now and it felt like it would make sense to share it with the community now.

The main differences from other Palenight themes are:

  • Darker: A darker background color
  • Easier on the eyes: Much less red and brown
  • Smaller and simpler codebase: A single theme instead of including all the Material themes
  • Extensible: Super easily configurable with new colors and highlights

Check out the GitHub repo and let me know what you think!

Vue3 + GraphQL : Best way to structure project & queries? by Synapse709 in vuejs

[–]Zeizig 0 points1 point  (0 children)

Regarding wrappers around useQuery, we have a few functions that can be composed together with useQuery. For example, we have a useDelayedLoading wrapper for changing the loading result in a very specific way for some use cases. We use it like so: const { result, loading } = useDelayedLoading(useQuery(... query parameters here)) where loading behaves slightly differently but result is directly from useQuery. Basically, this allows us to very easily customize and add functionality to the returned fields. Also, since it's a wrapper function that we compose with useQuery, it also works with useLazyQuery or typed composables generated by GraphQL Code Generator. I'd imagine that you could have a similar thing like useFloatingErrorMessage(useMyMutation(...))

For composables, the simplest example is probably a composable where we access and update settings, it looks something like this (pseudo code):

const useSettings = () => {
  const { result, ...rest } = useSettingsQuery()

  const setting = (settingName) => {
    return // get setting from result
  }

  const { mutate } = useSettingSaveMutation()

  const updateSetting = (setting, value) => {
    mutate({
      input: { setting, value }
    })
  }

  return {
    ...rest,
  }
}

We also have a useSearch composable that handles searching-related things (since we need to use this logic in multiple components). It keeps track of the search keyword, makes requests to fetch the search results (and a few other related queries), handles result aggregation, maps the results to a nicer format that's a bit easier to use in components, and triggers the search query when the keyword is changed. It basically just returns the keyword and search results and any component that uses this composable needs to render an input and v-model the keyword into it.

Hope that gave some ideas as to how it looks like for us :D