jose-elias-alvarez / typescript.nvim

A Lua plugin, written in TypeScript, to write TypeScript (Lua optional).
The Unlicense
498 stars 31 forks source link

A question about custom code actions #52

Closed rolfb closed 1 year ago

rolfb commented 1 year ago

Feels a bit odd to use Issues to post this so feel free to recommend a better way to ask and close this.

Given the contrived example code which will give the error Property 'container' does not exist on type {} on line 9:

import React from 'react'
import { StyleSheet, View } from 'react-native'

const styles = StyleSheet.create({
})

const Home = () => {
  return (
    <View style={styles.container} />
  )
}

Then I would like to have a code action to create the container key on styles as undefined (which would enable a jump to definition to change) or one which creates the container key and jumps the cursor to the value position and enters insert mode.

Is there a way to do this already? How could I go about creating this? Is it a good fit for this plugin? Perhaps better null-ls is a better fit? Any advice would be greatly appreciated. Given a sufficient amount of clues I can probably implement it myself.

Thanks!

jose-elias-alvarez commented 1 year ago

There are a few approaches that I can imagine:

  1. Implement this as a code action in typescript-language-server. We can then support it here, since the goal of this project is to support off-spec language server functionality in Neovim. I don't know how likely it is that they'll want to add this, though, since there's no matching code action in tsserver. This benefits the whole LSP ecosystem, but it requires more work.
  2. Implement this in tsserver, then add support in typescript-language-server. This is theoretically even better because it benefits the whole TypeScript ecosystem, but I imagine they are quite picky about which code actions they want to support, and it would take even more effort to push it through.
  3. Use null-ls. This is the lowest effort option, but it only benefits the Neovim ecosystem. If I were going to do this, I'd use Treesitter, though I'm not familiar enough with it to provide specific guidance.
rolfb commented 1 year ago

I'll give it a think and I guess the first step needs be getting it to work in principle with one of those either way. Closing the issue since I got some hints. Thanks for getting back to me!