Skip to content
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

docs: update LSP quickstart #28954

Merged
merged 3 commits into from
May 24, 2024
Merged

Conversation

gpanders
Copy link
Member

The LSP quickstart can act as our true "entrypoint" for answering the question "How do I use LSP in Neovim?" As such, it can be a little more beginniner-friendly than other sections of our help docs by including explanatory comments and a more fleshed out example (including a FileType autocommand).

This also includes some other minor wording updates and points users toward :checkhealth lsp.

The LSP quickstart can act as our true "entrypoint" for answering the
question "How do I use LSP in Neovim?" As such, it can be a little more
beginniner-friendly than other sections of our help docs by including
explanatory comments and a more fleshed out example (including a
`FileType` autocommand).

This also includes some other minor wording updates and points users
toward `:checkhealth lsp`.
@@ -25,24 +25,37 @@ Nvim provides an LSP client, but the servers are provided by third parties.
Follow these steps to get LSP features:

1. Install language servers using your package manager or by following the
upstream installation instruction. You can find language servers here:
upstream installation instructions. You can find language servers here:
https://microsoft.github.io/language-server-protocol/implementors/servers/
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to link to nvim-lspconfig instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not all users will have nvim-lspconfig installed, and in any case the hope here is that we can get more users to use LSP without it.

Copy link
Member

Choose a reason for hiding this comment

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

I was not suggesting replacing this by "use nvim-lspconfig", but to use their list of available servers instead since I think it will better reflect which LSPs currently have neovim support.
I don't have strong feelings about it though so it's fine.

@@ -25,24 +25,37 @@ Nvim provides an LSP client, but the servers are provided by third parties.
Follow these steps to get LSP features:

1. Install language servers using your package manager or by following the
upstream installation instruction. You can find language servers here:
upstream installation instructions. You can find language servers here:
https://microsoft.github.io/language-server-protocol/implementors/servers/

2. Configure the LSP client per language server. See |vim.lsp.start()| or use
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of this first sentence. If this is meant to be an introductory explanation, we should remain consistent of who's the client and who's the server.

Copy link
Member Author

Choose a reason for hiding this comment

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

Which sentence in particular? Do you have a suggestion on how to reword it?

Copy link
Member

Choose a reason for hiding this comment

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

Oh my bad, it seems like I didn't highlight the right line.
The sentence I don't like is "Configure the LSP client per language server". It makes the role of the client and server confusing IMO.
Maybe we can change it to "Configure each LSP server to communicate with the editor"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Reworded slightly in cd20761.


4. Configure keymaps and autocmds to use LSP features. See |lsp-config|.
4. (Optional) Configure keymaps and autocmds to use LSP features. |lsp-config|
Copy link
Member

Choose a reason for hiding this comment

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

For consistency with line 34:

Suggested change
4. (Optional) Configure keymaps and autocmds to use LSP features. |lsp-config|
4. (Optional) Configure keymaps and autocommands to use LSP features. |lsp-config|

name = 'my-server-name',
cmd = {'name-of-language-server-executable'},
root_dir = vim.fs.root(0, {'setup.py', 'pyproject.toml'}),
-- Create an event handler for the FileType autocommand
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: the "event handler" is the "autocommand" (in Vimspeak) for the FileType "event".

Of course, the question is how the audience is here -- whether we should "push" Vimspeak or generic protocol language.

Copy link
Member Author

@gpanders gpanders May 24, 2024

Choose a reason for hiding this comment

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

Trying to avoid Vim specific jargon here, where possible. We can leave lots of breadcrumbs (tags) to other help docs to guide the user to learn more, but at this point I want to assume as little a priori knowledge as possible.

-- This handler will fire when the buffer's 'filetype' is "python"
pattern = 'python',
callback = function(ev)
-- The buffer number this event is associated with
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend structuring these comments around the intention rather than a technical description. In this case, I would actually not define this here but use the event structure where it is needed (see below).

Copy link
Member Author

Choose a reason for hiding this comment

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

The intent here was to (hopefully) avoid confusion between "current buffer" and "buffer associated with the autocommand". Pulling the bufnr declaration out allows us to add a separate comment explaining this distinction. But perhaps this is not an important distinction for new users.

Comment on lines 46 to 49
-- The "root directory" of the project is the parent directory,
-- relative to the buffer's file, containing a "setup.py" or
-- "pyproject.toml" file
root_dir = vim.fs.root(bufnr, {'setup.py', 'pyproject.toml'}),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
-- The "root directory" of the project is the parent directory,
-- relative to the buffer's file, containing a "setup.py" or
-- "pyproject.toml" file
root_dir = vim.fs.root(bufnr, {'setup.py', 'pyproject.toml'}),
-- Set the "root directory" to the parent directory of the
-- file in the current buffer (`ev.buf`) that contains either
-- a "setup.py" or a "pyproject.toml" file
root_dir = vim.fs.root(ev.buf, {'setup.py', 'pyproject.toml'}),

@gpanders gpanders merged commit 28c0494 into neovim:master May 24, 2024
29 checks passed
@gpanders gpanders deleted the lsp-quickstart-update branch May 24, 2024 18:35
github-actions bot pushed a commit that referenced this pull request May 24, 2024
The LSP quickstart can act as our true "entrypoint" for answering the
question "How do I use LSP in Neovim?" As such, it can be a little more
beginniner-friendly than other sections of our help docs by including
explanatory comments and a more fleshed out example (including a
`FileType` autocommand).

This also includes some other minor wording updates and points users
toward `:checkhealth lsp`.

(cherry picked from commit 28c0494)
Copy link
Contributor

Successfully created backport PR for release-0.10:

gpanders added a commit that referenced this pull request May 24, 2024
docs: update LSP quickstart (#28954)

The LSP quickstart can act as our true "entrypoint" for answering the
question "How do I use LSP in Neovim?" As such, it can be a little more
beginniner-friendly than other sections of our help docs by including
explanatory comments and a more fleshed out example (including a
`FileType` autocommand).

This also includes some other minor wording updates and points users
toward `:checkhealth lsp`.

(cherry picked from commit 28c0494)

Co-authored-by: Gregory Anders <8965202+gpanders@users.noreply.github.com>
huangyingw pushed a commit to huangyingw/neovim that referenced this pull request May 31, 2024
The LSP quickstart can act as our true "entrypoint" for answering the
question "How do I use LSP in Neovim?" As such, it can be a little more
beginniner-friendly than other sections of our help docs by including
explanatory comments and a more fleshed out example (including a
`FileType` autocommand).

This also includes some other minor wording updates and points users
toward `:checkhealth lsp`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants