mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-24 09:47:19 +09:00
Hover support
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package lsp
|
||||
|
||||
import "github.com/sourcegraph/go-lsp"
|
||||
import (
|
||||
lsp "go.lsp.dev/protocol"
|
||||
"go.lsp.dev/uri"
|
||||
)
|
||||
|
||||
func (s *Server) DidOpen(filename, language, text string, version int) {
|
||||
func (s *Server) DidOpen(filename, language, text string, version *uint64) {
|
||||
doc := lsp.TextDocumentItem{
|
||||
URI: lsp.DocumentURI("file://" + filename),
|
||||
LanguageID: language,
|
||||
Version: version,
|
||||
URI: uri.File(filename),
|
||||
LanguageID: lsp.LanguageIdentifier(language),
|
||||
Version: float64(*version), // not sure why this is a float on go.lsp.dev
|
||||
Text: text,
|
||||
}
|
||||
|
||||
@@ -19,7 +22,7 @@ func (s *Server) DidOpen(filename, language, text string, version int) {
|
||||
|
||||
func (s *Server) DidSave(filename string) {
|
||||
doc := lsp.TextDocumentIdentifier{
|
||||
URI: lsp.DocumentURI("file://" + filename),
|
||||
URI: uri.File(filename),
|
||||
}
|
||||
|
||||
params := lsp.DidSaveTextDocumentParams{
|
||||
@@ -28,10 +31,10 @@ func (s *Server) DidSave(filename string) {
|
||||
go s.sendNotification("textDocument/didSave", params)
|
||||
}
|
||||
|
||||
func (s *Server) DidChange(filename string, version int, changes []lsp.TextDocumentContentChangeEvent) {
|
||||
func (s *Server) DidChange(filename string, version *uint64, changes []lsp.TextDocumentContentChangeEvent) {
|
||||
doc := lsp.VersionedTextDocumentIdentifier{
|
||||
TextDocumentIdentifier: lsp.TextDocumentIdentifier{
|
||||
URI: lsp.DocumentURI("file://" + filename),
|
||||
URI: uri.File(filename),
|
||||
},
|
||||
Version: version,
|
||||
}
|
||||
@@ -45,7 +48,7 @@ func (s *Server) DidChange(filename string, version int, changes []lsp.TextDocum
|
||||
|
||||
func (s *Server) DidClose(filename string) {
|
||||
doc := lsp.TextDocumentIdentifier{
|
||||
URI: lsp.DocumentURI("file://" + filename),
|
||||
URI: uri.File(filename),
|
||||
}
|
||||
|
||||
params := lsp.DidCloseTextDocumentParams{
|
||||
|
||||
@@ -3,7 +3,8 @@ package lsp
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/sourcegraph/go-lsp"
|
||||
lsp "go.lsp.dev/protocol"
|
||||
"go.lsp.dev/uri"
|
||||
)
|
||||
|
||||
type RPCCompletion struct {
|
||||
@@ -12,6 +13,19 @@ type RPCCompletion struct {
|
||||
Result lsp.CompletionList `json:"result"`
|
||||
}
|
||||
|
||||
type RPCHover struct {
|
||||
RPCVersion string `json:"jsonrpc"`
|
||||
ID int `json:"id"`
|
||||
Result lsp.Hover `json:"result"`
|
||||
}
|
||||
|
||||
func Position(x, y int) lsp.Position {
|
||||
return lsp.Position{
|
||||
Line: float64(y),
|
||||
Character: float64(x),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) DocumentFormat() {
|
||||
|
||||
}
|
||||
@@ -22,19 +36,19 @@ func (s *Server) DocumentRangeFormat() {
|
||||
|
||||
func (s *Server) Completion(filename string, pos lsp.Position) ([]lsp.CompletionItem, error) {
|
||||
cc := lsp.CompletionContext{
|
||||
TriggerKind: lsp.CTKInvoked,
|
||||
TriggerKind: lsp.Invoked,
|
||||
}
|
||||
|
||||
docpos := lsp.TextDocumentPositionParams{
|
||||
TextDocument: lsp.TextDocumentIdentifier{
|
||||
URI: lsp.DocumentURI("file://" + filename),
|
||||
URI: uri.File(filename),
|
||||
},
|
||||
Position: pos,
|
||||
}
|
||||
|
||||
params := lsp.CompletionParams{
|
||||
TextDocumentPositionParams: docpos,
|
||||
Context: cc,
|
||||
Context: &cc,
|
||||
}
|
||||
resp, err := s.sendRequest("textDocument/completion", params)
|
||||
if err != nil {
|
||||
@@ -53,3 +67,25 @@ func (s *Server) Completion(filename string, pos lsp.Position) ([]lsp.Completion
|
||||
func (s *Server) CompletionResolve() {
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) Hover(filename string, pos lsp.Position) (string, error) {
|
||||
params := lsp.TextDocumentPositionParams{
|
||||
TextDocument: lsp.TextDocumentIdentifier{
|
||||
URI: uri.File(filename),
|
||||
},
|
||||
Position: pos,
|
||||
}
|
||||
|
||||
resp, err := s.sendRequest("textDocument/hover", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r RPCHover
|
||||
err = json.Unmarshal(resp, &r)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.Result.Contents.Value, nil
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/sourcegraph/go-lsp"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
lsp "go.lsp.dev/protocol"
|
||||
"go.lsp.dev/uri"
|
||||
)
|
||||
|
||||
var activeServers map[string]*Server
|
||||
@@ -102,56 +102,36 @@ func StartServer(l Language) (*Server, error) {
|
||||
// The directory must be an absolute path
|
||||
func (s *Server) Initialize(directory string) {
|
||||
params := lsp.InitializeParams{
|
||||
ProcessID: os.Getpid(),
|
||||
RootURI: lsp.DocumentURI("file://" + directory),
|
||||
ClientInfo: lsp.ClientInfo{
|
||||
Name: "micro",
|
||||
Version: util.Version,
|
||||
},
|
||||
Trace: "off",
|
||||
ProcessID: float64(os.Getpid()),
|
||||
RootURI: uri.File(directory),
|
||||
Capabilities: lsp.ClientCapabilities{
|
||||
Workspace: lsp.WorkspaceClientCapabilities{
|
||||
WorkspaceEdit: struct {
|
||||
DocumentChanges bool `json:"documentChanges,omitempty"`
|
||||
ResourceOperations []string `json:"resourceOperations,omitempty"`
|
||||
}{
|
||||
Workspace: &lsp.WorkspaceClientCapabilities{
|
||||
WorkspaceEdit: &lsp.WorkspaceClientCapabilitiesWorkspaceEdit{
|
||||
DocumentChanges: true,
|
||||
ResourceOperations: []string{"create", "rename", "delete"},
|
||||
},
|
||||
ApplyEdit: true,
|
||||
},
|
||||
TextDocument: lsp.TextDocumentClientCapabilities{
|
||||
Formatting: &struct {
|
||||
DynamicRegistration bool `json:"dynamicRegistration,omitempty"`
|
||||
}{
|
||||
DynamicRegistration: true,
|
||||
TextDocument: &lsp.TextDocumentClientCapabilities{
|
||||
Formatting: &lsp.TextDocumentClientCapabilitiesFormatting{
|
||||
DynamicRegistration: false,
|
||||
},
|
||||
Completion: struct {
|
||||
CompletionItem struct {
|
||||
DocumentationFormat []lsp.DocumentationFormat `json:"documentationFormat,omitempty"`
|
||||
SnippetSupport bool `json:"snippetSupport,omitempty"`
|
||||
} `json:"completionItem,omitempty"`
|
||||
|
||||
CompletionItemKind struct {
|
||||
ValueSet []lsp.CompletionItemKind `json:"valueSet,omitempty"`
|
||||
} `json:"completionItemKind,omitempty"`
|
||||
|
||||
ContextSupport bool `json:"contextSupport,omitempty"`
|
||||
}{
|
||||
CompletionItem: struct {
|
||||
DocumentationFormat []lsp.DocumentationFormat `json:"documentationFormat,omitempty"`
|
||||
SnippetSupport bool `json:"snippetSupport,omitempty"`
|
||||
}{
|
||||
DocumentationFormat: []lsp.DocumentationFormat{lsp.DFPlainText},
|
||||
SnippetSupport: false,
|
||||
Completion: &lsp.TextDocumentClientCapabilitiesCompletion{
|
||||
DynamicRegistration: false,
|
||||
CompletionItem: &lsp.TextDocumentClientCapabilitiesCompletionItem{
|
||||
SnippetSupport: false,
|
||||
CommitCharactersSupport: false,
|
||||
DocumentationFormat: []lsp.MarkupKind{lsp.PlainText},
|
||||
DeprecatedSupport: false,
|
||||
PreselectSupport: false,
|
||||
},
|
||||
ContextSupport: false,
|
||||
},
|
||||
Hover: &lsp.TextDocumentClientCapabilitiesHover{
|
||||
DynamicRegistration: false,
|
||||
ContentFormat: []lsp.MarkupKind{lsp.PlainText},
|
||||
},
|
||||
},
|
||||
Window: lsp.WindowClientCapabilities{
|
||||
WorkDoneProgress: false,
|
||||
},
|
||||
Experimental: nil,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user