Day 30: Making My Own Diagnostic
đ° Mood: Frantically refreshing the live race results every hour on the hour for Bigâs Backyard Ultra. Currently 2 people left who have run 341 miles.
đ” Soundtrack: âwfh but make it jazzâ playlist
đ Reading Github Issues
Nothing exciting.
đ©ș Making My Own Diagnostic
After some other work stuff (boooooo), I got back to looking at gopls.
I was able to build gopls locally. (It was justgo install
, idk why I thought it would be
more complicated.) Then everything âjust workedâ. VSCode pointed to my version
and I added some fun âmeowsâ to the code to make sure.
I also learned that gopls has a CLI to test with so I donât need to reload VSCode every time. Plus I was able to use the CLI to figure out that I am looking to group diagnostics together. Knowing that term will come in handy when searching the code.
$ gopls check --help
show diagnostic results for the specified file
Usage: check [flags] <filename>
Example: show the diagnostic results of this file:
$ gopls check internal/lsp/cmd/check.go
$ gopls check main.go
main.go:62:3-4: MEOW redundant type from array, slice, or map composite literal
main.go:63:3-4: MEOW redundant type from array, slice, or map composite literal
main.go:64:3-4: MEOW redundant type from array, slice, or map composite literal
main.go:65:3-4: MEOW redundant type from array, slice, or map composite literal
Can you can tell itâs my dev version đ±??
I was poking through the code trying to figure out where to even start and I decided to learn how the code works by writing my own diagnostic. Initially my goal was to create a diagnostic that searched for the word âameliaâ (my name) in a comment and suggested replacing it with âameowliaâ (my screen name).
Of course all parsing is done via ASTs. I never had to use ASTs before this sabbatical. They have really come up a lot in all of the areas I have explored. I had trouble finding the comments in the AST and eventually I determined that it was because the code was parsed excluding comments. Ah.
I made a new goal to create a diagnostic that finds string variables with the word âameliaâ in them and replace âameliaâ with âameowliaâ.
I looked at this diagnostic for âno new varsâ and this one for simplifying composite literals for inspiration. And I was able to get something (very basic) working.
What is missing:
- Iâm struggling to get the quotes right when I replace it.
- Right now it replaces the whole string (including quotes) not just the part that says âameliaâ.
- All of the text descriptions are sloppy and are kinda bogus.
But it is progress!