Skip to content

Commit

Permalink
fix(typescript): only set ts keymaps for tsserver
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jan 10, 2023
1 parent 7406313 commit 2128bf3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lua/lazyvim/plugins/extras/lang/typescript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ return {
dependencies = {
"jose-elias-alvarez/typescript.nvim",
init = function()
require("lazyvim.util").on_attach(function(_, buffer)
-- stylua: ignore
vim.keymap.set( "n", "<leader>co", "TypescriptOrganizeImports", { buffer = buffer, desc = "Organize Imports" })
vim.keymap.set("n", "<leader>cR", "TypescriptRenameFile", { desc = "Rename File", buffer = buffer })
require("lazyvim.util").on_attach(function(server, buffer)
if server == "tsserver" then
-- stylua: ignore
vim.keymap.set( "n", "<leader>co", "TypescriptOrganizeImports", { buffer = buffer, desc = "Organize Imports" })
vim.keymap.set("n", "<leader>cR", "TypescriptRenameFile", { desc = "Rename File", buffer = buffer })
end
end)
end,
},
Expand Down

6 comments on commit 2128bf3

@appelgriebsch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity…. Is there also a way to override standard key maps such as ‘K’? For example would like to remap K for Rust to RustHoverActions… tried it with a custom init like you, but looks like the default mappings are always take preference…

@folke
Copy link
Collaborator Author

@folke folke commented on 2128bf3 Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@appelgriebsch That commit was actually wrong 😄
The first parameter to on_attach is the lsp client, not server name, so you need to check for client.name instead.

I fixed it in cce3129

I also moved it from init() inside the setup function, but init() should also work.

@amaanq
Copy link
Contributor

@amaanq amaanq commented on 2128bf3 Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity…. Is there also a way to override standard key maps such as ‘K’? For example would like to remap K for Rust to RustHoverActions… tried it with a custom init like you, but looks like the default mappings are always take preference…

I have RustHoverActions binded here, you could remap it in a fork of your own

of course dont forget

    { import = "lazyvim.plugins.extras.lang.rust" },

in your config

also, not to toot my own horn but I do think rust-tools would benefit a lot of ppl, #24 is up-to-date with the extras spec, but the keymap can be changed to whatever is more natural/"fits better" for ppl :)

@folke
Copy link
Collaborator Author

@folke folke commented on 2128bf3 Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amaanq you should check if the client is rust. You're also overriding the default cmp keymap for completion (<c-space>)

@amaanq
Copy link
Contributor

@amaanq amaanq commented on 2128bf3 Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're also overriding the default cmp keymap for completion

Oops..guess I should change that for myself after all

Edit: Thanks! Fixed here

@appelgriebsch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated my rust-lang module to enable K for RustHoverActions as well as crates documentation with much success. Thanks a lot!

Please sign in to comment.