1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
16 "golang.org/x/tools/internal/jsonrpc2"
17 "golang.org/x/tools/internal/lsp/protocol"
18 "golang.org/x/tools/internal/lsp/source"
19 "golang.org/x/tools/internal/span"
20 errors "golang.org/x/xerrors"
23 // Editor is a fake editor client. It keeps track of client state and can be
24 // used for writing LSP tests.
28 // Server, client, and sandbox are concurrency safe and written only
29 // at construction time, so do not require synchronization.
30 Server protocol.Server
31 serverConn jsonrpc2.Conn
34 defaultEnv map[string]string
36 // Since this editor is intended just for testing, we use very coarse
40 buffers map[string]buffer
41 // Capabilities / Options
42 serverCapabilities protocol.ServerCapabilities
51 func (b buffer) text() string {
52 return strings.Join(b.content, "\n")
55 // EditorConfig configures the editor's LSP session. This is similar to
56 // source.UserOptions, but we use a separate type here so that we expose only
57 // that configuration which we support.
59 // The zero value for EditorConfig should correspond to its defaults.
60 type EditorConfig struct {
64 // CodeLens is a map defining whether codelens are enabled, keyed by the
65 // codeLens command. CodeLens which are not present in this map are left in
66 // their default state.
67 CodeLens map[string]bool
69 // SymbolMatcher is the config associated with the "symbolMatcher" gopls
71 SymbolMatcher, SymbolStyle *string
73 // LimitWorkspaceScope is true if the user does not want to expand their
74 // workspace scope to the entire module.
75 LimitWorkspaceScope bool
77 // WithoutWorkspaceFolders is used to simulate opening a single file in the
78 // editor, without a workspace root. In that case, the client sends neither
79 // workspace folders nor a root URI.
80 WithoutWorkspaceFolders bool
82 // EditorRootPath specifies the root path of the workspace folder used when
83 // initializing gopls in the sandbox. If empty, the Workdir is used.
86 // EnableStaticcheck enables staticcheck analyzers.
87 EnableStaticcheck bool
89 // AllExperiments sets the "allExperiments" configuration, which enables
90 // all of gopls's opt-in settings.
94 // NewEditor Creates a new Editor.
95 func NewEditor(sandbox *Sandbox, config EditorConfig) *Editor {
97 buffers: make(map[string]buffer),
99 defaultEnv: sandbox.GoEnv(),
104 // Connect configures the editor to communicate with an LSP server on conn. It
105 // is not concurrency safe, and should be called at most once, before using the
108 // It returns the editor, so that it may be called as follows:
109 // editor, err := NewEditor(s).Connect(ctx, conn)
110 func (e *Editor) Connect(ctx context.Context, conn jsonrpc2.Conn, hooks ClientHooks) (*Editor, error) {
112 e.Server = protocol.ServerDispatcher(conn)
113 e.client = &Client{editor: e, hooks: hooks}
116 protocol.ClientHandler(e.client,
117 jsonrpc2.MethodNotFound)))
118 if err := e.initialize(ctx, e.Config.WithoutWorkspaceFolders, e.Config.EditorRootPath); err != nil {
121 e.sandbox.Workdir.AddWatcher(e.onFileChanges)
125 // Shutdown issues the 'shutdown' LSP notification.
126 func (e *Editor) Shutdown(ctx context.Context) error {
128 if err := e.Server.Shutdown(ctx); err != nil {
129 return errors.Errorf("Shutdown: %w", err)
135 // Exit issues the 'exit' LSP notification.
136 func (e *Editor) Exit(ctx context.Context) error {
138 // Not all LSP clients issue the exit RPC, but we do so here to ensure that
139 // we gracefully handle it on multi-session servers.
140 if err := e.Server.Exit(ctx); err != nil {
141 return errors.Errorf("Exit: %w", err)
147 // Close issues the shutdown and exit sequence an editor should.
148 func (e *Editor) Close(ctx context.Context) error {
149 if err := e.Shutdown(ctx); err != nil {
152 if err := e.Exit(ctx); err != nil {
155 // called close on the editor should result in the connection closing
157 case <-e.serverConn.Done():
158 // connection closed itself
161 return errors.Errorf("connection not closed: %w", ctx.Err())
165 // Client returns the LSP client for this editor.
166 func (e *Editor) Client() *Client {
170 func (e *Editor) overlayEnv() map[string]string {
171 env := make(map[string]string)
172 for k, v := range e.defaultEnv {
175 for k, v := range e.Config.Env {
181 func (e *Editor) configuration() map[string]interface{} {
182 config := map[string]interface{}{
183 "verboseWorkDoneProgress": true,
184 "env": e.overlayEnv(),
185 "expandWorkspaceToModule": !e.Config.LimitWorkspaceScope,
186 "completionBudget": "10s",
189 if e.Config.BuildFlags != nil {
190 config["buildFlags"] = e.Config.BuildFlags
193 if e.Config.CodeLens != nil {
194 config["codelens"] = e.Config.CodeLens
196 if e.Config.SymbolMatcher != nil {
197 config["symbolMatcher"] = *e.Config.SymbolMatcher
199 if e.Config.SymbolStyle != nil {
200 config["symbolStyle"] = *e.Config.SymbolStyle
202 if e.Config.EnableStaticcheck {
203 config["staticcheck"] = true
205 if e.Config.AllExperiments {
206 config["allExperiments"] = true
209 // TODO(rFindley): uncomment this if/when diagnostics delay is on by
210 // default... and probably change to the new settings name.
211 // config["experimentalDiagnosticsDelay"] = "10ms"
213 // ExperimentalWorkspaceModule is only set as a mode, not a configuration.
217 func (e *Editor) initialize(ctx context.Context, withoutWorkspaceFolders bool, editorRootPath string) error {
218 params := &protocol.ParamInitialize{}
219 params.ClientInfo.Name = "fakeclient"
220 params.ClientInfo.Version = "v1.0.0"
221 if !withoutWorkspaceFolders {
222 rootURI := e.sandbox.Workdir.RootURI()
223 if editorRootPath != "" {
224 rootURI = toURI(e.sandbox.Workdir.AbsPath(editorRootPath))
226 params.WorkspaceFolders = []protocol.WorkspaceFolder{{
227 URI: string(rootURI),
228 Name: filepath.Base(rootURI.SpanURI().Filename()),
231 params.Capabilities.Workspace.Configuration = true
232 params.Capabilities.Window.WorkDoneProgress = true
233 // TODO: set client capabilities
234 params.InitializationOptions = e.configuration()
236 // This is a bit of a hack, since the fake editor doesn't actually support
237 // watching changed files that match a specific glob pattern. However, the
238 // editor does send didChangeWatchedFiles notifications, so set this to
240 params.Capabilities.Workspace.DidChangeWatchedFiles.DynamicRegistration = true
242 params.Trace = "messages"
243 // TODO: support workspace folders.
245 resp, err := e.Server.Initialize(ctx, params)
247 return errors.Errorf("initialize: %w", err)
250 e.serverCapabilities = resp.Capabilities
253 if err := e.Server.Initialized(ctx, &protocol.InitializedParams{}); err != nil {
254 return errors.Errorf("initialized: %w", err)
257 // TODO: await initial configuration here, or expect gopls to manage that?
261 func (e *Editor) onFileChanges(ctx context.Context, evts []FileEvent) {
265 var lspevts []protocol.FileEvent
266 for _, evt := range evts {
267 lspevts = append(lspevts, evt.ProtocolEvent)
269 e.Server.DidChangeWatchedFiles(ctx, &protocol.DidChangeWatchedFilesParams{
274 // OpenFile creates a buffer for the given workdir-relative file.
275 func (e *Editor) OpenFile(ctx context.Context, path string) error {
276 content, err := e.sandbox.Workdir.ReadFile(path)
280 return e.CreateBuffer(ctx, path, content)
283 func newBuffer(path, content string) buffer {
287 content: strings.Split(content, "\n"),
291 func textDocumentItem(wd *Workdir, buf buffer) protocol.TextDocumentItem {
292 uri := wd.URI(buf.path)
294 if strings.HasSuffix(buf.path, ".go") {
295 // TODO: what about go.mod files? What is their language ID?
298 return protocol.TextDocumentItem{
300 LanguageID: languageID,
301 Version: float64(buf.version),
306 // CreateBuffer creates a new unsaved buffer corresponding to the workdir path,
307 // containing the given textual content.
308 func (e *Editor) CreateBuffer(ctx context.Context, path, content string) error {
309 buf := newBuffer(path, content)
311 e.buffers[path] = buf
312 item := textDocumentItem(e.sandbox.Workdir, buf)
316 if err := e.Server.DidOpen(ctx, &protocol.DidOpenTextDocumentParams{
319 return errors.Errorf("DidOpen: %w", err)
325 // CloseBuffer removes the current buffer (regardless of whether it is saved).
326 func (e *Editor) CloseBuffer(ctx context.Context, path string) error {
328 _, ok := e.buffers[path]
331 return ErrUnknownBuffer
333 delete(e.buffers, path)
337 if err := e.Server.DidClose(ctx, &protocol.DidCloseTextDocumentParams{
338 TextDocument: e.textDocumentIdentifier(path),
340 return errors.Errorf("DidClose: %w", err)
346 func (e *Editor) textDocumentIdentifier(path string) protocol.TextDocumentIdentifier {
347 return protocol.TextDocumentIdentifier{
348 URI: e.sandbox.Workdir.URI(path),
352 // SaveBuffer writes the content of the buffer specified by the given path to
354 func (e *Editor) SaveBuffer(ctx context.Context, path string) error {
355 if err := e.OrganizeImports(ctx, path); err != nil {
356 return errors.Errorf("organizing imports before save: %w", err)
358 if err := e.FormatBuffer(ctx, path); err != nil {
359 return errors.Errorf("formatting before save: %w", err)
361 return e.SaveBufferWithoutActions(ctx, path)
364 func (e *Editor) SaveBufferWithoutActions(ctx context.Context, path string) error {
366 buf, ok := e.buffers[path]
369 return fmt.Errorf(fmt.Sprintf("unknown buffer: %q", path))
371 content := buf.text()
373 syncOptions, ok := e.serverCapabilities.TextDocumentSync.(protocol.TextDocumentSyncOptions)
375 includeText = syncOptions.Save.IncludeText
379 docID := e.textDocumentIdentifier(buf.path)
381 if err := e.Server.WillSave(ctx, &protocol.WillSaveTextDocumentParams{
383 Reason: protocol.Manual,
385 return errors.Errorf("WillSave: %w", err)
388 if err := e.sandbox.Workdir.WriteFile(ctx, path, content); err != nil {
389 return errors.Errorf("writing %q: %w", path, err)
392 params := &protocol.DidSaveTextDocumentParams{
393 TextDocument: protocol.VersionedTextDocumentIdentifier{
394 Version: float64(buf.version),
395 TextDocumentIdentifier: docID,
399 params.Text = &content
401 if err := e.Server.DidSave(ctx, params); err != nil {
402 return errors.Errorf("DidSave: %w", err)
408 // contentPosition returns the (Line, Column) position corresponding to offset
409 // in the buffer referenced by path.
410 func contentPosition(content string, offset int) (Pos, error) {
411 scanner := bufio.NewScanner(strings.NewReader(content))
415 end := start + len([]rune(scanner.Text())) + 1
417 return Pos{Line: line, Column: offset - start}, nil
422 if err := scanner.Err(); err != nil {
423 return Pos{}, errors.Errorf("scanning content: %w", err)
425 // Scan() will drop the last line if it is empty. Correct for this.
426 if (strings.HasSuffix(content, "\n") || content == "") && offset == start {
427 return Pos{Line: line, Column: 0}, nil
429 return Pos{}, fmt.Errorf("position %d out of bounds in %q (line = %d, start = %d)", offset, content, line, start)
432 // ErrNoMatch is returned if a regexp search fails.
434 ErrNoMatch = errors.New("no match")
435 ErrUnknownBuffer = errors.New("unknown buffer")
438 // regexpRange returns the start and end of the first occurrence of either re
439 // or its singular subgroup. It returns ErrNoMatch if the regexp doesn't match.
440 func regexpRange(content, re string) (Pos, Pos, error) {
442 rec, err := regexp.Compile(re)
444 return Pos{}, Pos{}, err
446 indexes := rec.FindStringSubmatchIndex(content)
448 return Pos{}, Pos{}, ErrNoMatch
450 switch len(indexes) {
452 // no subgroups: return the range of the regexp expression
453 start, end = indexes[0], indexes[1]
455 // one subgroup: return its range
456 start, end = indexes[2], indexes[3]
458 return Pos{}, Pos{}, fmt.Errorf("invalid search regexp %q: expect either 0 or 1 subgroups, got %d", re, len(indexes)/2-1)
460 startPos, err := contentPosition(content, start)
462 return Pos{}, Pos{}, err
464 endPos, err := contentPosition(content, end)
466 return Pos{}, Pos{}, err
468 return startPos, endPos, nil
471 // RegexpRange returns the first range in the buffer bufName matching re. See
472 // RegexpSearch for more information on matching.
473 func (e *Editor) RegexpRange(bufName, re string) (Pos, Pos, error) {
476 buf, ok := e.buffers[bufName]
478 return Pos{}, Pos{}, ErrUnknownBuffer
480 return regexpRange(buf.text(), re)
483 // RegexpSearch returns the position of the first match for re in the buffer
484 // bufName. For convenience, RegexpSearch supports the following two modes:
485 // 1. If re has no subgroups, return the position of the match for re itself.
486 // 2. If re has one subgroup, return the position of the first subgroup.
487 // It returns an error re is invalid, has more than one subgroup, or doesn't
489 func (e *Editor) RegexpSearch(bufName, re string) (Pos, error) {
490 start, _, err := e.RegexpRange(bufName, re)
494 // RegexpReplace edits the buffer corresponding to path by replacing the first
495 // instance of re, or its first subgroup, with the replace text. See
496 // RegexpSearch for more explanation of these two modes.
497 // It returns an error if re is invalid, has more than one subgroup, or doesn't
499 func (e *Editor) RegexpReplace(ctx context.Context, path, re, replace string) error {
502 buf, ok := e.buffers[path]
504 return ErrUnknownBuffer
506 content := buf.text()
507 start, end, err := regexpRange(content, re)
511 return e.editBufferLocked(ctx, path, []Edit{{
518 // EditBuffer applies the given test edits to the buffer identified by path.
519 func (e *Editor) EditBuffer(ctx context.Context, path string, edits []Edit) error {
522 return e.editBufferLocked(ctx, path, edits)
525 // BufferText returns the content of the buffer with the given name.
526 func (e *Editor) BufferText(name string) string {
529 return e.buffers[name].text()
532 // BufferVersion returns the current version of the buffer corresponding to
533 // name (or 0 if it is not being edited).
534 func (e *Editor) BufferVersion(name string) int {
537 return e.buffers[name].version
540 func (e *Editor) editBufferLocked(ctx context.Context, path string, edits []Edit) error {
541 buf, ok := e.buffers[path]
543 return fmt.Errorf("unknown buffer %q", path)
546 content = make([]string, len(buf.content))
548 evts []protocol.TextDocumentContentChangeEvent
550 copy(content, buf.content)
551 content, err = editContent(content, edits)
556 buf.content = content
558 e.buffers[path] = buf
559 // A simple heuristic: if there is only one edit, send it incrementally.
560 // Otherwise, send the entire content.
562 evts = append(evts, edits[0].toProtocolChangeEvent())
564 evts = append(evts, protocol.TextDocumentContentChangeEvent{
568 params := &protocol.DidChangeTextDocumentParams{
569 TextDocument: protocol.VersionedTextDocumentIdentifier{
570 Version: float64(buf.version),
571 TextDocumentIdentifier: e.textDocumentIdentifier(buf.path),
573 ContentChanges: evts,
576 if err := e.Server.DidChange(ctx, params); err != nil {
577 return errors.Errorf("DidChange: %w", err)
583 // GoToDefinition jumps to the definition of the symbol at the given position
584 // in an open buffer.
585 func (e *Editor) GoToDefinition(ctx context.Context, path string, pos Pos) (string, Pos, error) {
586 if err := e.checkBufferPosition(path, pos); err != nil {
587 return "", Pos{}, err
589 params := &protocol.DefinitionParams{}
590 params.TextDocument.URI = e.sandbox.Workdir.URI(path)
591 params.Position = pos.ToProtocolPosition()
593 resp, err := e.Server.Definition(ctx, params)
595 return "", Pos{}, errors.Errorf("definition: %w", err)
598 return "", Pos{}, nil
600 newPath := e.sandbox.Workdir.URIToPath(resp[0].URI)
601 newPos := fromProtocolPosition(resp[0].Range.Start)
602 if err := e.OpenFile(ctx, newPath); err != nil {
603 return "", Pos{}, errors.Errorf("OpenFile: %w", err)
605 return newPath, newPos, nil
608 // Symbol performs a workspace symbol search using query
609 func (e *Editor) Symbol(ctx context.Context, query string) ([]SymbolInformation, error) {
610 params := &protocol.WorkspaceSymbolParams{}
613 resp, err := e.Server.Symbol(ctx, params)
615 return nil, errors.Errorf("symbol: %w", err)
617 var res []SymbolInformation
618 for _, si := range resp {
620 path := e.sandbox.Workdir.URIToPath(ploc.URI)
621 start := fromProtocolPosition(ploc.Range.Start)
622 end := fromProtocolPosition(ploc.Range.End)
631 res = append(res, SymbolInformation{
640 // OrganizeImports requests and performs the source.organizeImports codeAction.
641 func (e *Editor) OrganizeImports(ctx context.Context, path string) error {
642 return e.codeAction(ctx, path, nil, nil, protocol.SourceOrganizeImports)
645 // RefactorRewrite requests and performs the source.refactorRewrite codeAction.
646 func (e *Editor) RefactorRewrite(ctx context.Context, path string, rng *protocol.Range) error {
647 return e.codeAction(ctx, path, rng, nil, protocol.RefactorRewrite)
650 // ApplyQuickFixes requests and performs the quickfix codeAction.
651 func (e *Editor) ApplyQuickFixes(ctx context.Context, path string, rng *protocol.Range, diagnostics []protocol.Diagnostic) error {
652 return e.codeAction(ctx, path, rng, diagnostics, protocol.QuickFix, protocol.SourceFixAll)
655 func (e *Editor) codeAction(ctx context.Context, path string, rng *protocol.Range, diagnostics []protocol.Diagnostic, only ...protocol.CodeActionKind) error {
659 params := &protocol.CodeActionParams{}
660 params.TextDocument.URI = e.sandbox.Workdir.URI(path)
661 params.Context.Only = only
662 if diagnostics != nil {
663 params.Context.Diagnostics = diagnostics
668 actions, err := e.Server.CodeAction(ctx, params)
670 return errors.Errorf("textDocument/codeAction: %w", err)
672 for _, action := range actions {
674 for _, o := range only {
675 if action.Kind == o {
683 for _, change := range action.Edit.DocumentChanges {
684 path := e.sandbox.Workdir.URIToPath(change.TextDocument.URI)
685 if float64(e.buffers[path].version) != change.TextDocument.Version {
686 // Skip edits for old versions.
689 edits := convertEdits(change.Edits)
690 if err := e.EditBuffer(ctx, path, edits); err != nil {
691 return errors.Errorf("editing buffer %q: %w", path, err)
694 // Execute any commands. The specification says that commands are
695 // executed after edits are applied.
696 if action.Command != nil {
697 if _, err := e.ExecuteCommand(ctx, &protocol.ExecuteCommandParams{
698 Command: action.Command.Command,
699 Arguments: action.Command.Arguments,
708 func (e *Editor) ExecuteCommand(ctx context.Context, params *protocol.ExecuteCommandParams) (interface{}, error) {
713 // Ensure that this command was actually listed as a supported command.
714 for _, command := range e.serverCapabilities.ExecuteCommandProvider.Commands {
715 if command == params.Command {
721 return nil, fmt.Errorf("unsupported command %q", params.Command)
723 return e.Server.ExecuteCommand(ctx, params)
726 func convertEdits(protocolEdits []protocol.TextEdit) []Edit {
728 for _, lspEdit := range protocolEdits {
729 edits = append(edits, fromProtocolTextEdit(lspEdit))
734 // FormatBuffer gofmts a Go file.
735 func (e *Editor) FormatBuffer(ctx context.Context, path string) error {
740 version := e.buffers[path].version
742 params := &protocol.DocumentFormattingParams{}
743 params.TextDocument.URI = e.sandbox.Workdir.URI(path)
744 resp, err := e.Server.Formatting(ctx, params)
746 return errors.Errorf("textDocument/formatting: %w", err)
750 if versionAfter := e.buffers[path].version; versionAfter != version {
751 return fmt.Errorf("before receipt of formatting edits, buffer version changed from %d to %d", version, versionAfter)
753 edits := convertEdits(resp)
754 return e.editBufferLocked(ctx, path, edits)
757 func (e *Editor) checkBufferPosition(path string, pos Pos) error {
760 buf, ok := e.buffers[path]
762 return fmt.Errorf("buffer %q is not open", path)
764 if !inText(pos, buf.content) {
765 return fmt.Errorf("position %v is invalid in buffer %q", pos, path)
770 // RunGenerate runs `go generate` non-recursively in the workdir-relative dir
771 // path. It does not report any resulting file changes as a watched file
772 // change, so must be followed by a call to Workdir.CheckForFileChanges once
773 // the generate command has completed.
774 func (e *Editor) RunGenerate(ctx context.Context, dir string) error {
778 absDir := e.sandbox.Workdir.AbsPath(dir)
779 jsonArgs, err := source.MarshalArgs(span.URIFromPath(absDir), false)
783 params := &protocol.ExecuteCommandParams{
784 Command: source.CommandGenerate.ID(),
787 if _, err := e.ExecuteCommand(ctx, params); err != nil {
788 return fmt.Errorf("running generate: %v", err)
790 // Unfortunately we can't simply poll the workdir for file changes here,
791 // because server-side command may not have completed. In regtests, we can
792 // Await this state change, but here we must delegate that responsibility to
797 // CodeLens executes a codelens request on the server.
798 func (e *Editor) CodeLens(ctx context.Context, path string) ([]protocol.CodeLens, error) {
803 _, ok := e.buffers[path]
806 return nil, fmt.Errorf("buffer %q is not open", path)
808 params := &protocol.CodeLensParams{
809 TextDocument: e.textDocumentIdentifier(path),
811 lens, err := e.Server.CodeLens(ctx, params)
818 // Completion executes a completion request on the server.
819 func (e *Editor) Completion(ctx context.Context, path string, pos Pos) (*protocol.CompletionList, error) {
824 _, ok := e.buffers[path]
827 return nil, fmt.Errorf("buffer %q is not open", path)
829 params := &protocol.CompletionParams{
830 TextDocumentPositionParams: protocol.TextDocumentPositionParams{
831 TextDocument: e.textDocumentIdentifier(path),
832 Position: pos.ToProtocolPosition(),
835 completions, err := e.Server.Completion(ctx, params)
839 return completions, nil
842 // References executes a reference request on the server.
843 func (e *Editor) References(ctx context.Context, path string, pos Pos) ([]protocol.Location, error) {
848 _, ok := e.buffers[path]
851 return nil, fmt.Errorf("buffer %q is not open", path)
853 params := &protocol.ReferenceParams{
854 TextDocumentPositionParams: protocol.TextDocumentPositionParams{
855 TextDocument: e.textDocumentIdentifier(path),
856 Position: pos.ToProtocolPosition(),
858 Context: protocol.ReferenceContext{
859 IncludeDeclaration: true,
862 locations, err := e.Server.References(ctx, params)
866 return locations, nil
869 // CodeAction executes a codeAction request on the server.
870 func (e *Editor) CodeAction(ctx context.Context, path string, rng *protocol.Range) ([]protocol.CodeAction, error) {
875 _, ok := e.buffers[path]
878 return nil, fmt.Errorf("buffer %q is not open", path)
880 params := &protocol.CodeActionParams{
881 TextDocument: e.textDocumentIdentifier(path),
886 lens, err := e.Server.CodeAction(ctx, params)
893 // Hover triggers a hover at the given position in an open buffer.
894 func (e *Editor) Hover(ctx context.Context, path string, pos Pos) (*protocol.MarkupContent, Pos, error) {
895 if err := e.checkBufferPosition(path, pos); err != nil {
896 return nil, Pos{}, err
898 params := &protocol.HoverParams{}
899 params.TextDocument.URI = e.sandbox.Workdir.URI(path)
900 params.Position = pos.ToProtocolPosition()
902 resp, err := e.Server.Hover(ctx, params)
904 return nil, Pos{}, errors.Errorf("hover: %w", err)
907 return nil, Pos{}, nil
909 return &resp.Contents, fromProtocolPosition(resp.Range.Start), nil
912 func (e *Editor) DocumentLink(ctx context.Context, path string) ([]protocol.DocumentLink, error) {
916 params := &protocol.DocumentLinkParams{}
917 params.TextDocument.URI = e.sandbox.Workdir.URI(path)
918 return e.Server.DocumentLink(ctx, params)