gogetdoc
gogetdoc copied to clipboard
"couldn't find _ in program" if -modified and file doesn't exist
Scenario: editing a .go file that's hasn't been saved yet. (For example, for rapid greenfield prototyping of stuff via some sort of go run-based REPL-ish tool like gore.) The source is sent as usual via -modified flag and stdin archive format. When -pos is something like Untitled-1.go:#pos, all documentation requests via -json (say, hovering over the strings.ToLower or anything that should have docs) will always return couldn't find Untitled-1 in program. Or if name is empty, similarly couldn't find in program (2 spaces).
Here's an easy-repro session:
[23:42 me ~/.../github.com/metaleap]$ gogetdoc -json -modified -pos untitled.go:#94
untitled.go
136
package tmp
import "strings"
func test (val string) string {
if val[0]=='u' {return strings.ToUpper(val)}
return "Nope not happn'g"
}
gogetdoc: couldn't find untitled.go in program
[23:49 me ~/.../github.com/metaleap]$
Of course no file named untitled.go exists on disk, but would be awesome if gogetdoc could handle that, given that it read the program from stdin anyway! The given -pos 94 should be between the T and o of ToUpper if my editor didn't fool me.
Oddly enough, just found that guru too gives a strikingly similarly worded message in such a scenario: file Untitled-1 not found in loaded program --- makes me wonder, why look for any file when it's supplied via stdin though!
Good catch - I had never even considered such a scenario.
I'll take a look this week.
Ever got the chance? ;D
Sadly, as you might suspect, I did not. Would happily take a PR to fix this.