From f99204d0e13f41ce3065c1cdc2278db6db7a776a Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Mon, 7 Oct 2024 21:33:35 -0700 Subject: [PATCH] open source of generated files, not the generated file, for errors and other links. --- code/editor.go | 1 + code/files.go | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/code/editor.go b/code/editor.go index ae972ad6..0fa66dba 100644 --- a/code/editor.go +++ b/code/editor.go @@ -414,6 +414,7 @@ func (cv *Code) OpenFileURL(ur string, ftv *texteditor.Editor) bool { } } pos := up.Fragment + tv, _, ok := cv.LinkViewFile(core.Filename(fpath)) if !ok { _, fnm := filepath.Split(fpath) diff --git a/code/files.go b/code/files.go index e58229c8..4432d4d5 100644 --- a/code/files.go +++ b/code/files.go @@ -12,6 +12,7 @@ import ( "time" "cogentcore.org/core/base/fileinfo" + "cogentcore.org/core/base/fsx" "cogentcore.org/core/core" "cogentcore.org/core/events" "cogentcore.org/core/filetree" @@ -319,13 +320,34 @@ func (cv *Code) LinkViewFileNode(fn *filetree.Node) (*TextEditor, int) { return tv, idx } +// GeneratedFileExts are file extensions for the source file that generates +// another file. If a file is opened that is marked as generated, this list is +// used to look for another file with the same name and the source extention, +// and it is opened instead. +var GeneratedFileExts = map[string]string{ + ".goal": ".go", +} + // LinkViewFile opens the file in the 2nd texteditor, which is next to // the tabs where links are clicked, if it is not collapsed -- else 1st func (cv *Code) LinkViewFile(fnm core.Filename) (*TextEditor, int, bool) { - fn := cv.FileNodeForFile(string(fnm), true) + fn := cv.FileNodeForFile(string(fnm), true) // add if not found if fn == nil { return nil, -1, false } + if fn.Info.Generated { + bfnm, ext := fsx.ExtSplit(string(fnm)) + for ex, fex := range GeneratedFileExts { + if fex == ext { + nfnm := bfnm + ex + nfn := cv.FileNodeForFile(nfnm, false) + if nfn != nil { + fn = nfn + break + } + } + } + } tv, idx, ok := cv.TextEditorForFileNode(fn) if ok { if idx == 1 {