Skip to content

Commit

Permalink
many updates to code: fixed All find to be much faster; direct access…
Browse files Browse the repository at this point in the history
… to debug params in debugger; replace prefs -> settings; replace GoGi -> Cogent Core
  • Loading branch information
rcoreilly committed Jan 22, 2024
1 parent 5b2006c commit a7aa5b2
Show file tree
Hide file tree
Showing 38 changed files with 388 additions and 333 deletions.
4 changes: 2 additions & 2 deletions code/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
![alt tag](logo/code_icon.png)

**Code** is a flexible IDE (integrated development environment) framework in pure Go, using the [GoGi](https://cogentcore.org/core/gi) GUI (for which it serves as a continuous testing platform :) and the [GoPi](https://cogentcore.org/core/pi) interactive parser for syntax highlighting and more advanced IDE code processing.
**Code** is a flexible IDE (integrated development environment) framework in pure Go, using the [Cogent Core](https://cogentcore.org/core/gi) GUI (for which it serves as a continuous testing platform :) and the [GoPi](https://cogentcore.org/core/pi) interactive parser for syntax highlighting and more advanced IDE code processing.

See the [Wiki](https://cogentcore.org/cogent/code/wiki) for more docs, [Install](https://cogentcore.org/cogent/code/wiki/Install) instructions (`go install cogentcore.org/cogent/code/cmd/code@latest` should work if GoGi system libraries are in place), and [Google Groups goki-gi](https://groups.google.com/forum/#!forum/goki-gi) emailing list.
See the [Wiki](https://cogentcore.org/cogent/code/wiki) for more docs, [Install](https://cogentcore.org/cogent/code/wiki/Install) instructions (`go install cogentcore.org/cogent/code/cmd/code@latest` should work if Cogent Core system libraries are in place), and [Google Groups goki-gi](https://groups.google.com/forum/#!forum/goki-gi) emailing list.

[![Go Report Card](https://goreportcard.com/badge/cogentcore.org/cogent/code/v2)](https://goreportcard.com/report/cogentcore.org/cogent/code/v2)
[![GoDoc](https://godoc.org/cogentcore.org/cogent/code/v2?status.svg)](https://godoc.org/cogentcore.org/cogent/code/v2)
Expand Down
7 changes: 5 additions & 2 deletions code/cdebug/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,18 @@ type VarParams struct {
}

// Params are overall debugger parameters
type Params struct {
type Params struct { //gti:add

// mode for running the debugger
Mode Modes `xml:"-" toml:"-" json:"-" view:"-"`

// process id number to attach to, for Attach mode
PID uint64 `xml:"-" toml:"-" json:"-" view:"-"`

// optional extra args to pass to the debugger. Use double-dash -- and then add args to pass args to the executable (double-dash is by itself as a separate arg first)
// optional extra args to pass to the debugger.
// Use -- double-dash and then add args to pass args to the executable
// (double-dash is by itself as a separate arg first).
// For Debug test, must use -test.run instead of plain -run to specify tests to run.
Args []string

// status function for debugger updating status
Expand Down
2 changes: 1 addition & 1 deletion code/cmd/pie/pie.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main
func main() {
/*
goosi.TheApp.SetName("pie")
goosi.TheApp.SetAbout(`<code>Pie</code> is the interactive parser (pi) editor written in the <b>GoGi</b> graphical interface system, within the <b>Goki</b> tree framework. See <a href="https://cogentcore.org/core/pi">Code on GitHub</a> and <a href="https://cogentcore.org/core/pi/wiki">Code wiki</a> for documentation.<br>
goosi.TheApp.SetAbout(`<code>Pie</code> is the interactive parser (pi) editor written in the <b>Cogent Core</b> graphical interface system, within the <b>Goki</b> tree framework. See <a href="https://cogentcore.org/core/pi">Code on GitHub</a> and <a href="https://cogentcore.org/core/pi/wiki">Code wiki</a> for documentation.<br>
<br>
Version: ` + pi.VersionInfo())
Expand Down
2 changes: 1 addition & 1 deletion code/code/argvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var ArgVars = map[string]ArgVarInfo{
type ArgVarVals map[string]string

// Set sets the current values for arg variables -- prompts must be already set!
func (avp *ArgVarVals) Set(fpath string, ppref *ProjPrefs, tv *texteditor.Editor) {
func (avp *ArgVarVals) Set(fpath string, ppref *ProjSettings, tv *texteditor.Editor) {
if *avp == nil {
*avp = make(ArgVarVals, len(ArgVars))
}
Expand Down
2 changes: 1 addition & 1 deletion code/code/argvars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestBind(t *testing.T) {
fpath := "/Users/oreilly/go/src/cogentcore.org/cogent/code/argvars_test.go"
projpath := "/Users/oreilly/go/src/github.com"

pp := ProjPrefs{}
pp := ProjSettings{}
pp.ProjRoot = gi.Filename(projpath)

var avp ArgVarVals
Expand Down
13 changes: 8 additions & 5 deletions code/code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
type Code interface {
gi.Widget

// ProjPrefs returns the code.ProjPrefs
ProjPrefs() *ProjPrefs
// ProjSettings returns the code.ProjSettings
ProjSettings() *ProjSettings

// FileTree returns the code.Files file tree
FileTree() *filetree.Tree
Expand All @@ -37,7 +37,7 @@ type Code interface {
LastSaveTime() time.Time

// VersCtrl returns the version control system in effect, using the file tree detected
// version or whatever is set in project preferences
// version or whatever is set in project settings
VersCtrl() filetree.VersCtrlName

// CmdRuns returns the CmdRuns manager of running commands, used extensively
Expand Down Expand Up @@ -87,7 +87,7 @@ type Code interface {
// ActiveTextEditor returns the currently-active TextEditor
ActiveTextEditor() *TextEditor

// SetActiveTextEditor sets the given textview as the active one, and returns its index
// SetActiveTextEditor sets the given texteditor as the active one, and returns its index
SetActiveTextEditor(av *TextEditor) int

// ActiveFileNode returns the file node for the active file -- nil if none
Expand Down Expand Up @@ -130,8 +130,11 @@ type Code interface {
// called prior to rename.
CloseOpenNodes(nodes []*FileNode)

// CurOpenNodes returns the current open nodes list
CurOpenNodes() *OpenNodes

// LookupFun is the completion system Lookup function that makes a custom
// textview dialog that has option to edit resulting file.
// texteditor dialog that has option to edit resulting file.
LookupFun(data any, text string, posLn, posCh int) (ld complete.Lookup)

// Spell checks spelling in active text view
Expand Down
6 changes: 3 additions & 3 deletions code/code/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ func MarkupCmdOutput(out []byte) []byte {
type Commands []*Command

// CmdName has an associated ValueView for selecting from the list of
// available command names, for use in preferences etc.
// available command names, for use in settings etc.
// Formatted as Cat: Name as in Command.Label()
type CmdName string

Expand Down Expand Up @@ -676,7 +676,7 @@ func (cn *CmdNames) Add(cmd CmdName) {
// the same names.
var AvailCmds Commands

// CustomCmds is user-specific list of commands saved in preferences available
// CustomCmds is user-specific list of commands saved in settings available
// for all Code projects. These will override StdCmds with the same names.
var CustomCmds = Commands{}

Expand Down Expand Up @@ -723,7 +723,7 @@ func (cm *Commands) CmdByName(name CmdName, msg bool) (*Command, int, bool) {
return nil, -1, false
}

// PrefsCmdsFilename is the name of the preferences file in App prefs
// PrefsCmdsFilename is the name of the settings file in App prefs
// directory for saving / loading your CustomCmds commands list
var PrefsCmdsFilename = "command_prefs.toml"

Expand Down
14 changes: 11 additions & 3 deletions code/code/debugview.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var Debuggers = map[fi.Known]func(path, rootPath string, outbuf *texteditor.Buf,
func NewDebugger(sup fi.Known, path, rootPath string, outbuf *texteditor.Buf, pars *cdebug.Params) (cdebug.GiDebug, error) {
df, ok := Debuggers[sup]
if !ok {
err := fmt.Errorf("Gi Debug: File type %v not supported -- change the MainLang in File/Project Prefs.. to a supported language (Go only option so far)", sup)
err := fmt.Errorf("Gi Debug: File type %v not supported -- change the MainLang in File/Project Settings.. to a supported language (Go only option so far)", sup)
log.Println(err)
return nil, err
}
Expand Down Expand Up @@ -173,8 +173,8 @@ func (dv *DebugView) Start() {
if dv.Dbg != nil {
dv.Detach()
}
rootPath := string(dv.Code.ProjPrefs().ProjRoot)
pars := &dv.Code.ProjPrefs().Debug
rootPath := string(dv.Code.ProjSettings().ProjRoot)
pars := &dv.Code.ProjSettings().Debug
dv.State.Mode = pars.Mode
pars.StatFunc = func(stat cdebug.Status) {
updt := dv.UpdateStartAsync()
Expand Down Expand Up @@ -933,6 +933,14 @@ func (dv *DebugView) ConfigToolbar() {
OnClick(func(e events.Event) {
giv.CallFunc(dv, dv.ListGlobalVars)
})

gi.NewButton(tb).SetText("Params").SetIcon(icons.Edit).
SetTooltip("edit the debugger parameters (e.g., for passing args: use -- (double dash) to separate args passed to program vs. those passed to the debugger itself)").
StyleFirst(func(s *styles.Style) { s.SetEnabled(dv.DbgIsAvail()) }).
OnClick(func(e events.Event) {
DebugSettingsView(&dv.Code.ProjSettings().Debug)
})

}

//////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion code/code/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// Package code provides all the code infrastructure and supporting gui
// for filetree, commands, console, and 2-sequence key functions,
// preferences, splitviews, etc.
// settings, splitviews, etc.
//
// CodeView is in a separate codev directory so that other packages can
// tap into the code infrastructure, and be callable directly from the
Expand Down
28 changes: 14 additions & 14 deletions code/code/enumgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 27 additions & 12 deletions code/code/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (fn *FileNode) SetRunExec() {
}
ge, ok := ParentCode(fn.This())
if ok {
ge.ProjPrefs().RunExec = fn.FPath
ge.ProjPrefs().BuildDir = gi.Filename(filepath.Dir(string(fn.FPath)))
ge.ProjSettings().RunExec = fn.FPath
ge.ProjSettings().BuildDir = gi.Filename(filepath.Dir(string(fn.FPath)))
}
}

Expand Down Expand Up @@ -237,6 +237,16 @@ func (on *OpenNodes) NChanged() int {
return cnt
}

// FindPath finds node for given path, nil if not found
func (on *OpenNodes) FindPath(path string) *filetree.Node {
for _, f := range *on {
if f.FPath == gi.Filename(path) {
return f
}
}
return nil
}

//////////////////////////////////////////////////////////////////////////
// Search

Expand All @@ -250,14 +260,14 @@ type FileSearchResults struct {
// FileTreeSearch returns list of all nodes starting at given node of given
// language(s) that contain the given string, sorted in descending order by number
// of occurrences -- ignoreCase transforms everything into lowercase
func FileTreeSearch(start *filetree.Node, find string, ignoreCase, regExp bool, loc FindLoc, activeDir string, langs []fi.Known) []FileSearchResults {
func FileTreeSearch(ge Code, start *filetree.Node, find string, ignoreCase, regExp bool, loc FindLoc, activeDir string, langs []fi.Known) []FileSearchResults {
fb := []byte(find)
fsz := len(find)
if fsz == 0 {
return nil
}
if loc == FindLocAll {
return FindAll(start, find, ignoreCase, regExp, langs)
return FindAll(ge, start, find, ignoreCase, regExp, langs)
}
var re *regexp.Regexp
var err error
Expand Down Expand Up @@ -331,7 +341,7 @@ func FileTreeSearch(start *filetree.Node, find string, ignoreCase, regExp bool,
// starting at given node of given language(s) that contain the given string,
// sorted in descending order by number of occurrences. ignoreCase transforms
// everything into lowercase.
func FindAll(start *filetree.Node, find string, ignoreCase, regExp bool, langs []fi.Known) []FileSearchResults {
func FindAll(ge Code, start *filetree.Node, find string, ignoreCase, regExp bool, langs []fi.Known) []FileSearchResults {
fb := []byte(find)
fsz := len(find)
if fsz == 0 {
Expand Down Expand Up @@ -374,14 +384,14 @@ func FindAll(start *filetree.Node, find string, ignoreCase, regExp bool, langs [
return nil
}
}
sfn, found := start.FindFile(path)
ofn := ge.CurOpenNodes().FindPath(path)
var cnt int
var matches []textbuf.Match
if found && sfn.IsOpen() && sfn.Buf != nil {
if ofn != nil && ofn.Buf != nil {
if regExp {
cnt, matches = sfn.Buf.SearchRegexp(re)
cnt, matches = ofn.Buf.SearchRegexp(re)
} else {
cnt, matches = sfn.Buf.Search(fb, ignoreCase, false)
cnt, matches = ofn.Buf.Search(fb, ignoreCase, false)
}
} else {
if regExp {
Expand All @@ -391,10 +401,15 @@ func FindAll(start *filetree.Node, find string, ignoreCase, regExp bool, langs [
}
}
if cnt > 0 {
if found {
mls = append(mls, FileSearchResults{sfn, cnt, matches})
if ofn != nil {
mls = append(mls, FileSearchResults{ofn, cnt, matches})
} else {
fmt.Println("file not found in FindFile:", path)
sfn, found := start.FindFile(path)
if found {
mls = append(mls, FileSearchResults{sfn, cnt, matches})
} else {
fmt.Println("file not found in FindFile:", path)
}
}
}
return nil
Expand Down
10 changes: 5 additions & 5 deletions code/code/findview.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (
type FindLoc int32 //enums:enum -trim-prefix FindLoc

const (
// FindLocAll finds in all directories under the root path
FindLocAll FindLoc = iota

// FindOpen finds in all open folders in the left file browser
FindLocOpen
FindLocOpen FindLoc = iota

// FindLocAll finds in all directories under the root path. can be slow for large file trees
FindLocAll

// FindLocFile only finds in the current active file
FindLocFile
Expand Down Expand Up @@ -94,7 +94,7 @@ type FindView struct {

// Params returns the find params
func (fv *FindView) Params() *FindParams {
return &fv.Code.ProjPrefs().Find
return &fv.Code.ProjSettings().Find
}

// ShowResults shows the results in the buffer
Expand Down
Loading

0 comments on commit a7aa5b2

Please sign in to comment.