首页 > 解决方案 > Configuring Vim/Neovim ALE plugin to support :ALEGoToDefinition in JavaScript files

问题描述

I installed the ALE plugin for Vim using vim-plug:

Plug 'dense-analysis/ale'

The plugin seems to have been installed correctly. I can use ALE to automatically format files with Prettier, for example. But I can't seem to get anything that uses the language server to work.

For example, in the following JavaScript file, putting my cursor over the name add on line 5 and using the :ALEGoToDefinition command has no effect.

function add(x, y) {
  return x + y;
}

console.log(add(1, 2));

I have really made an effort to read the documentation. The ALE help file says that "ALE will do nothing" if an LSP server does not provide a location to jump to. That seems to be my problem. But the ALE documentation on GitHub also says that "ALE integrates with almost all JavaScript tools very well, and most things should work without requiring any configuration."

I must be missing something. Aside from installing ALE, is anything needed to enable features which use a language server? Should I install some kind of language server globally on my machine?

标签: vimvim-pluginlanguage-server-protocol

解决方案


User toupeira on Reddit answered this question for me. At the time of this writing, the only JavaScript language server that ALE supports is tsserver. It ships with TypeScript. To enable ALE's language server features, I needed to install the typescript package globally.

npm install -g typescript

I don't need to start the server manually. ALE seems to take care of that.

The only other requirement is that tsserver is enabled as a JavaScript "linter." It is by default. Run :ALEInfo to see which linters are enabled for the current file.


推荐阅读