blob: bc6f3414feb4fbb17737ae8ec57367e4861fb1d0 [file] [log] [blame] [view]
Rebecca Stambler43ba1fe2019-06-18 12:52:27 -04001What follows is a list of questions/ideas/suggestions for folks looking to integrate `gopls` within an editor/similar.
2
3A good starting point for any integrator is the [Language Service Protocol Specification](https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md). [`golang.org/x/tools/internal/lsp/protocol`](https://godoc.org/golang.org/x/tools/internal/lsp/protocol) represents a Go definition of the spec.
4
5## What does `gopls` support?
6
7The most accurate answer to this question is to examine the `InitializeResult` response to [`Initialize`](https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md#initialize-request-leftwards_arrow_with_hook), specifically the `capabilities` field of type `ServerCapabilities`
8
9## UTF-8, UTF-16 and position information
10
11As an example, the [`Hover`](https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md#hover-request-leftwards_arrow_with_hook) method takes [`TextDocumentPositionParams `](https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md#textdocumentpositionparams) which has a `position` field of type [`Position`](https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md#text-documents). The key point to note from that last link is the following:
12
13> A position inside a document (see Position definition below) is expressed as a zero-based line and character offset. The offsets are based on a UTF-16 string representation. So a string of the form a𐐀b the character offset of the character a is 0, the character offset of 𐐀 is 1 and the character offset of b is 3 since 𐐀 is represented using two code units in UTF-16.
14
15i.e. integrators will need to calculate UTF-16 based column offsets. For Go-based integrators, the [`golang.org/x/tools/internal/span`](https://godoc.org/golang.org/x/tools/internal/span#NewPoint) will be of use. [#31080](https://github.com/golang/go/issues/31080) tracks making `span` and other useful packages non-internal.
16
Suzy Muellera89d1ce2019-07-15 18:23:39 -040017## `[]TextEdit` responses
Rebecca Stambler43ba1fe2019-06-18 12:52:27 -040018
Suzy Muellera89d1ce2019-07-15 18:23:39 -040019At the time of writing (2019-07-15) the [`[]TextEdit`](https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md#textedit) response to [`textDocument/formatting`](https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md#document-formatting-request--leftwards_arrow_with_hook) and the [`WorkspaceEdit`](https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md#workspaceedit) response to [`textDocument/rename`](https://github.com/Microsoft/language-server-protocol/blob/gh-pages/specification.md#textDocument_rename) comprises range-based deltas. The spec is not explicit about how these deltas should be applied, instead simply stating:
Rebecca Stambler43ba1fe2019-06-18 12:52:27 -040020
21> If multiple inserts have the same position, the order in the array defines the order in which the inserted strings appear in the resulting text.
22
Suzy Muellera89d1ce2019-07-15 18:23:39 -040023All `[]TextEdit` are sorted such that applying the array of deltas received in reverse order achieves the desired result that holds with the spec.
Rebecca Stambler43ba1fe2019-06-18 12:52:27 -040024
25## RPC response errors
26
27https://go-review.googlesource.com/c/tools/+/170958 and related discussions are looking to help shape what it means for a server method to return an error. i.e.
28
29* Under what conditions would the `Format` method return an error?
30* On a syntax error, or just for low-level LSP/transport issues?
31* What should editors do in response to such errors?
32
33This answer is therefore a WIP.
34
35## Files that change "outside the editor"
36
37For example, files that are created/modified/removed as a result of `go generate`. Per [@ianthehat](https://github.com/ianthehat):
38
39> The plan is to have the client do all the work for us. Specifically we are going to start using `workspace/didChangeWatchedFiles` to monitor all the files we are caching AST's for
40
41This is currently not implemented (see [#31553](https://github.com/golang/go/issues/31553)).