@ -29,6 +29,7 @@ type Server struct {
templateLoader core . TemplateLoader
fs core . FileStorage
logger util . Logger
useAdditionalTextEdits opt . Bool
}
// ServerOpts holds the options to create a new Server.
@ -66,6 +67,7 @@ func NewServer(opts ServerOpts) *Server {
templateLoader : opts . TemplateLoader ,
fs : fs ,
logger : opts . Logger ,
useAdditionalTextEdits : opt . NullBool ,
}
var clientCapabilities protocol . ClientCapabilities
@ -79,6 +81,15 @@ func NewServer(opts ServerOpts) *Server {
protocol . SetTraceValue ( * params . Trace )
}
if params . ClientInfo != nil {
if params . ClientInfo . Name == "Visual Studio Code" {
// Visual Studio Code doesn't seem to support inl
// VSCode doesn't support deleting the trigger characters with
// the main TextEdit. We'll use additional text edits instead.
server . useAdditionalTextEdits = opt . True
}
}
capabilities := handler . CreateServerCapabilities ( )
capabilities . HoverProvider = true
capabilities . DefinitionProvider = true
@ -792,6 +803,7 @@ func (s *Server) newCompletionItem(notebook *core.Notebook, note core.MinimalNot
return item , err
}
if s . useAdditionalTextEditsWithNotebook ( notebook ) {
addTextEdits := [ ] protocol . TextEdit { }
// Some LSP clients (e.g. VSCode) don't support deleting the trigger
@ -803,6 +815,7 @@ func (s *Server) newCompletionItem(notebook *core.Notebook, note core.MinimalNot
} )
item . AdditionalTextEdits = addTextEdits
}
return item , nil
}
@ -822,6 +835,12 @@ func (s *Server) newTextEditForLink(notebook *core.Notebook, note core.MinimalNo
return nil , err
}
// Overwrite [[ trigger directly if the additional text edits are disabled.
startOffset := 0
if ! s . useAdditionalTextEditsWithNotebook ( notebook ) {
startOffset = - 2
}
// Some LSP clients (e.g. VSCode) auto-pair brackets, so we need to
// remove the closing ]] or )) after the completion.
endOffset := 0
@ -832,10 +851,17 @@ func (s *Server) newTextEditForLink(notebook *core.Notebook, note core.MinimalNo
return protocol . TextEdit {
NewText : link ,
Range : rangeFromPosition ( pos , 0 , endOffset ) ,
Range : rangeFromPosition ( pos , startOffset , endOffset ) ,
} , nil
}
func ( s * Server ) useAdditionalTextEditsWithNotebook ( nb * core . Notebook ) bool {
return nb . Config . LSP . Completion . UseAdditionalTextEdits .
Or ( s . useAdditionalTextEdits ) .
OrBool ( false ) .
Unwrap ( )
}
func positionInRange ( content string , rng protocol . Range , pos protocol . Position ) bool {
start , end := rng . IndexesIn ( content )
i := pos . IndexIn ( content )