Skip to content

Can't use TSX support in LanguageClient-neovim #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cormacrelf opened this issue Nov 14, 2018 · 11 comments
Closed

Can't use TSX support in LanguageClient-neovim #90

cormacrelf opened this issue Nov 14, 2018 · 11 comments

Comments

@cormacrelf
Copy link

cormacrelf commented Nov 14, 2018

The languageId -> TS/TSX function only supports the languageIds used in VSCode. They are typescript, and typescriptreact for TSX.

In Vim, however, the convention is to use typescript.tsx, which means editing tsx files either doesn't work (typescript.tsx), or spews forth thousands of syntax errors (with just typescript). That option isn't configurable in LanguageClient-neovim, it must use the &filetype variable.

Could that function be amended to recognise the Vim form as well? Same goes for javascript.jsx.

@alextes
Copy link

alextes commented Jan 3, 2019

@cormacrelf are you sure? The following appears to work fine for me:

let g:LanguageClient_serverCommands = {
      \ 'typescript': ['~/.node-bin/javascript-typescript-langserver', '--stdio'],
      \ 'typescript.tsx': ['~/.node-bin/javascript-typescript-langserver', '--stdio'],
      \}

@cormacrelf
Copy link
Author

That’s what I did. You do have to be in a file with TSX in it.

@alextes
Copy link

alextes commented Jan 3, 2019

Seems to be working fine too @cormacrelf . Did you try logging the client and server output?

screen shot 2019-01-03 at 23 33 53

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNEXT",
    "module": "commonjs",
    "jsx": "preserve",
    "strict": true,
    "allowSyntheticDefaultImports": false,
    "esModuleInterop": true
  }
}

@BenoitZugmeyer
Copy link

I have the same issue, but I guess this is because leafgarland/typescript-vim does not set the filetype to typescript.tsx yet, see leafgarland/typescript-vim#140

@alextes
Copy link

alextes commented Jan 9, 2019

Ah, now I understand the point @cormacrelf was making! Indeed, I use HerringtonDarkholme/yats.vim, it sets typescript.tsx.

@BenoitZugmeyer
Copy link

BenoitZugmeyer commented Jan 9, 2019

There is way too many TS vim plugins, and it seems the one from leafgarland is the most popular (most github stars) but not the most complete/effective (no TSX syntax highlighting, ...). I'll try yats.vim, thanks for sharing!

@everett1992
Copy link

Why does the file type need to be typescript.tsx to enable tsx support from the language server? I was bit by this because I use leafgarland/typescript-vim so my filetype was typescript.

wincent added a commit to wincent/wincent that referenced this issue Aug 3, 2019
Without the "typescript.tsx" filetype, typescript-language-server won't
pass the `--jsx` option to TypeScript, which causes it to think that
imported components aren't actually used:

    import Foo from './Foo'; // 'Foo' is declared but its value is never read.

    export default function X() {
      return <Foo />;
    }

and probably a bunch of other problems as well.

typescript-language-server/typescript-language-server#90
@tsujp
Copy link

tsujp commented Sep 20, 2019

I'm having problem using typescript react with sublime LSP also, any fixes available nothing in this issue worked.

@tillydray
Copy link

@tsujp Add this line to your vimrc:

autocmd BufNewFile,BufRead *.tsx setlocal filetype=typescript.tsx.

I found this suggestion here. It did the trick.

If you want to know more about what the line does, search the help docs for autocmd :h autocmd. Basically any time a new file is being created or a file is being read, and it's a tsx file, it sets the filetype to typescript.tsx. You could do something silly and change css filetypes to js to see what happens.

@ta3pks
Copy link

ta3pks commented Nov 9, 2020

alternatively adding a modeline is also an option instead of a autocmd I dont event have typescript.vim I dont really know why I am having this issue tho :D

@rchl
Copy link
Member

rchl commented Jul 3, 2021

The clients have to adjust to languageIds supported by this server, not the other way around. The IDs are pretty standardized these days across clients.

As for Sublime Text, you might just want to assign the TSX syntax to all typescript files. That shouldn't cause issues for plain TS files.

@rchl rchl closed this as completed Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants