-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code action for OPA fmt #630
Conversation
Signed-off-by: Anders Eknert <anders@styra.com>
Signed-off-by: Charlie Egan <charlie@styra.com>
Signed-off-by: Charlie Egan <charlie@styra.com>
e6ecb4c
to
a3a6a42
Compare
func FmtCommand(args []string) Command { | ||
return Command{ | ||
Title: "Format using opa-fmt", | ||
Command: "regal.fmt", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you happen to know if there's a well-known command name or some other mechanism at play when an IDE/editor does "format on save" via LSP? What I'm wondering is what we'd need to do to have that just work. If it's command-name-based, we'd need to adjust this. But I know way too little about LSP myself 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://zed.dev/docs/configuring-zed#lsp this makes me think there's no convention...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yeah, that'll be trivial to add with this code in place as the response is the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not the most competent reviewer, but I've reviewed it anyways 🙃 (except for the copied-over diff parts)
internal/lsp/server.go
Outdated
@@ -121,6 +134,8 @@ func (l *LanguageServer) Handle( | |||
return struct{}{}, nil | |||
} | |||
|
|||
fmt.Fprintf(l.errorLog, "%s\n", string(util.MustMarshalJSON(req))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt.Fprintf(l.errorLog, "%s\n", string(util.MustMarshalJSON(req))) | |
fmt.Fprintln(l.errorLog, string(util.MustMarshalJSON(req))) |
(if it was desired to keep this line)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I don't think we need this tbh. Will remove, I have some ideas to improve the logging in the server, but will do in another PR.
for _, diag := range params.Context.Diagnostics { | ||
if diag.Code == "opa-fmt" { | ||
actions = append(actions, CodeAction{ | ||
Title: "Format using opa fmt", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool ✨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Left a few comments, but nothing big.
This is not really the best place to do this, so I'll do it properly in another PR. Signed-off-by: Charlie Egan <charlie@styra.com>
This is now used where it's used in the spec. Signed-off-by: Charlie Egan <charlie@styra.com>
Signed-off-by: Charlie Egan <charlie@styra.com>
While working on #630, I needed to be able to see requests, responses and notifications to the server from the client and from the server to the client. I learned that there is functionality in the jsonrpc2 lib that we use to do this nicely. This PR implements a new logging configuration to make use of this using an adapted version of the LogMessage function that is found in the library and using the OnRecv and OnSend functions. Because of this, I have removed the logging responsibility from the server and moved it to the connection. The server now should log errors only and that should be the default mode of operation. Enabling verbose logging will show you all messages being sent on the connection. ExcludeMethods and IncludeMethods can be used to filter the stream of messages when you are interested in monitoring or ignoring certain flows of messages. I know that this will be useful for me and I hope that this is a sensible enough way to do this overall. Signed-off-by: Charlie Egan <charlie@styra.com>
* Refactor LSP logging While working on #630, I needed to be able to see requests, responses and notifications to the server from the client and from the server to the client. I learned that there is functionality in the jsonrpc2 lib that we use to do this nicely. This PR implements a new logging configuration to make use of this using an adapted version of the LogMessage function that is found in the library and using the OnRecv and OnSend functions. Because of this, I have removed the logging responsibility from the server and moved it to the connection. The server now should log errors only and that should be the default mode of operation. Enabling verbose logging will show you all messages being sent on the connection. ExcludeMethods and IncludeMethods can be used to filter the stream of messages when you are interested in monitoring or ignoring certain flows of messages. I know that this will be useful for me and I hope that this is a sensible enough way to do this overall. Signed-off-by: Charlie Egan <charlie@styra.com> * Inline logging config Signed-off-by: Charlie Egan <charlie@styra.com> * Remove VerboseLogging server option for good Also use an io.Writer for errors Signed-off-by: Charlie Egan <charlie@styra.com> --------- Signed-off-by: Charlie Egan <charlie@styra.com>
* WIP code action Signed-off-by: Anders Eknert <anders@styra.com> * Support sending of workspace/applyEdits Signed-off-by: Charlie Egan <charlie@styra.com> * Fix linter errors Signed-off-by: Charlie Egan <charlie@styra.com> * Remove logging of unknown messages This is not really the best place to do this, so I'll do it properly in another PR. Signed-off-by: Charlie Egan <charlie@styra.com> * Add OptionalVersionedTextDocumentIdentifier This is now used where it's used in the spec. Signed-off-by: Charlie Egan <charlie@styra.com> * Add license for ComputeEdits Signed-off-by: Charlie Egan <charlie@styra.com> --------- Signed-off-by: Anders Eknert <anders@styra.com> Signed-off-by: Charlie Egan <charlie@styra.com> Co-authored-by: Anders Eknert <anders@styra.com>
* Refactor LSP logging While working on StyraInc#630, I needed to be able to see requests, responses and notifications to the server from the client and from the server to the client. I learned that there is functionality in the jsonrpc2 lib that we use to do this nicely. This PR implements a new logging configuration to make use of this using an adapted version of the LogMessage function that is found in the library and using the OnRecv and OnSend functions. Because of this, I have removed the logging responsibility from the server and moved it to the connection. The server now should log errors only and that should be the default mode of operation. Enabling verbose logging will show you all messages being sent on the connection. ExcludeMethods and IncludeMethods can be used to filter the stream of messages when you are interested in monitoring or ignoring certain flows of messages. I know that this will be useful for me and I hope that this is a sensible enough way to do this overall. Signed-off-by: Charlie Egan <charlie@styra.com> * Inline logging config Signed-off-by: Charlie Egan <charlie@styra.com> * Remove VerboseLogging server option for good Also use an io.Writer for errors Signed-off-by: Charlie Egan <charlie@styra.com> --------- Signed-off-by: Charlie Egan <charlie@styra.com>
Screen.Recording.2024-04-10.at.11.31.26.mov