Skip to content

Commit

Permalink
WIP broken
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone committed Jan 22, 2025
1 parent ae202e9 commit 1909188
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
75 changes: 75 additions & 0 deletions internal/lsp/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,75 @@ func (state *State) handleHover(params HoverParams) *Hover {
}
}

func (state *State) handleCodeAction(params CodeActionParams) *CodeAction {

// position := fromLspPosition(params.Position)

// doc, ok := state.documents[params.TextDocument.URI]
// if !ok {
// return nil
// }

// hoverable := analysis.HoverOn(doc.CheckResult.Program, position)

// switch hoverable := hoverable.(type) {
// case *analysis.VariableHover:

// varLit := hoverable.Node
// resolution := doc.CheckResult.ResolveVar(varLit)

// os.Stderr.Write([]byte("HI!"))

// bs, _ := json.Marshal(params)
// os.Stderr.Write(bs)
return &CodeAction{
Title: "EXAMPLE code action",
Kind: Refactor,
Edit: WorkspaceEdit{

// DocumentChanges: []TextDocumentEdit{
// {
// Edits: []TextEdit{
// {
// NewText: "HELLO!",
// Range: Range{
// Start: Position{0, 0},
// End: Position{0, 1},
// },
// },
// },
// TextDocument: OptionalVersionedTextDocumentIdentifier{
// TextDocumentIdentifier: TextDocumentIdentifier{
// URI: params.TextDocument.URI,
// },
// },
// },

// string(params.TextDocument.URI): {
// {
// NewText: "HELLO!",
// Range: Range{
// Start: Position{0, 0},
// End: Position{0, 1},
// },
// },
// },
// },
Changes: map[string][]TextEdit{
string(params.TextDocument.URI): {
{
NewText: "HELLO!",
Range: Range{
Start: Position{0, 0},
End: Position{0, 10},
},
},
},
},
},
}
}

func (state *State) handleGotoDefinition(params DefinitionParams) *Location {
doc, ok := state.documents[params.TextDocument.URI]
if !ok {
Expand Down Expand Up @@ -170,6 +239,7 @@ func Handle(r jsonrpc2.Request, state *State) any {
HoverProvider: true,
DefinitionProvider: true,
DocumentSymbolProvider: true,
CodeActionProvider: true,
},
// This is ugly. Is there a shortcut?
ServerInfo: struct {
Expand Down Expand Up @@ -199,6 +269,11 @@ func Handle(r jsonrpc2.Request, state *State) any {
json.Unmarshal([]byte(*r.Params), &p)
return state.handleHover(p)

case "textDocument/codeAction":
var p CodeActionParams
json.Unmarshal([]byte(*r.Params), &p)
return state.handleCodeAction(p)

case "textDocument/definition":
var p DefinitionParams
json.Unmarshal([]byte(*r.Params), &p)
Expand Down
1 change: 0 additions & 1 deletion internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func SendNotification(method string, params interface{}) {
Method: method,
Params: &rawParams,
})
os.Stderr.Write([]byte(encoded))
_, err = fmt.Print(encoded)
if err != nil {
panic(err)
Expand Down

0 comments on commit 1909188

Please sign in to comment.