Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
file maps working for almost all languages, but decided not to include config files in map. also include references/removals check in anchors call to catch non-standard references/removals
Dane Schneidera85236286d7d
diff --git a/app/cli/cmd/apply.go b/app/cli/cmd/apply.goindex ad40607d..c97bfc3f 100644--- a/app/cli/cmd/apply.go+++ b/app/cli/cmd/apply.go@@ -8,7 +8,7 @@ import ("github.com/spf13/cobra")-var autoConfirm, autoCommit, noCommit bool+var autoCommit, noCommit boolfunc init() {applyCmd.Flags().BoolVarP(&autoCommit, "commit", "c", false, "Commit changes to git")diff --git a/app/cli/cmd/tell.go b/app/cli/cmd/tell.goindex b90f17b0..57e4ffb8 100644--- a/app/cli/cmd/tell.go+++ b/app/cli/cmd/tell.go@@ -25,6 +25,8 @@ import (const defaultEditor = "vim"+var autoConfirm bool+// const defaultEditor = "nano"var tellPromptFile stringdiff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.goindex e829980c..d3e9dfd5 100644--- a/app/cli/lib/context_load.go+++ b/app/cli/lib/context_load.go@@ -271,7 +271,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {if params.DefsOnly {for _, path := range flattenedPaths {ext := filepath.Ext(path)- if shared.IsTreeSitterExtension(ext) {+ if shared.HasFileMapSupport(ext) {numPaths++}}@@ -311,7 +311,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {}ext := filepath.Ext(path)- if !shared.IsTreeSitterExtension(ext) {+ if !shared.HasFileMapSupport(ext) {// not a tree-sitter supported extensioncontinue}diff --git a/app/cli/lib/context_update.go b/app/cli/lib/context_update.goindex 5c0f38fd..1927f80b 100644--- a/app/cli/lib/context_update.go+++ b/app/cli/lib/context_update.go@@ -6,7 +6,6 @@ import ("fmt""log""os"- "path/filepath""plandex/api""plandex/fs""plandex/term"@@ -416,8 +415,7 @@ func checkOutdatedAndMaybeUpdateContext(doUpdate bool, maybeContexts []*shared.CflattenedPaths = filteredPathsfor _, path := range flattenedPaths {- ext := filepath.Ext(path)- if !shared.IsTreeSitterExtension(ext) {+ if !shared.HasFileMapSupport(path) {continue}diff --git a/app/server/db/context_helpers.go b/app/server/db/context_helpers.goindex dcb9dff7..6d2b6138 100644--- a/app/server/db/context_helpers.go+++ b/app/server/db/context_helpers.go@@ -9,7 +9,7 @@ import ("log""os""path/filepath"- "plandex-server/syntax"+ "plandex-server/syntax/file_map""sort""strings""sync"@@ -305,7 +305,7 @@ func LoadContexts(ctx Ctx, params LoadContextsParams) (*shared.LoadContextResponif context.ContextType == shared.ContextMapType && len(context.MapInputs) > 0 {// Process file maps- mappedFiles, err := syntax.ProcessMapFiles(ctx, context.MapInputs)+ mappedFiles, err := file_map.ProcessMapFiles(ctx, context.MapInputs)if err != nil {return nil, nil, fmt.Errorf("error processing map files: %v", err)}diff --git a/app/server/go.mod b/app/server/go.modindex 490dd967..836308a5 100644--- a/app/server/go.mod+++ b/app/server/go.mod@@ -8,7 +8,7 @@ require (github.com/gorilla/mux v1.8.1github.com/pkg/errors v0.9.1github.com/plandex/plandex/shared v0.0.0-00010101000000-000000000000- github.com/sashabaranov/go-openai v1.35.6+ github.com/sashabaranov/go-openai v1.35.7)require (@@ -30,21 +30,22 @@ require (github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirectgo.uber.org/atomic v1.11.0 // indirectgolang.org/x/image v0.22.0 // indirect- golang.org/x/sys v0.24.0 // indirect+ golang.org/x/sys v0.27.0 // indirectgopkg.in/yaml.v3 v3.0.1 // indirect)require (github.com/atotto/clipboard v0.1.4github.com/aws/aws-sdk-go v1.55.5- github.com/fatih/color v1.17.0+ github.com/fatih/color v1.18.0github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4- github.com/golang-migrate/migrate/v4 v4.17.1+ github.com/golang-migrate/migrate/v4 v4.18.1github.com/jmoiron/sqlx v1.4.0github.com/lib/pq v1.10.9- github.com/rs/cors v1.11.0- github.com/smacker/go-tree-sitter v0.0.0-20240625050157-a31a98a7c0f6- github.com/stretchr/testify v1.8.3+ github.com/rs/cors v1.11.1+ github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82+ github.com/stretchr/testify v1.10.0+ golang.org/x/net v0.31.0)replace github.com/plandex/plandex/shared => ../shareddiff --git a/app/server/go.sum b/app/server/go.sumindex 3d942f07..b42caf1d 100644--- a/app/server/go.sum+++ b/app/server/go.sum@@ -2,8 +2,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=-github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=-github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=+github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=+github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=@@ -11,22 +11,28 @@ github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQgithub.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=-github.com/dhui/dktest v0.4.1 h1:/w+IWuDXVymg3IrRJCHHOkMK10m9aNVMOyD0X12YVTg=-github.com/dhui/dktest v0.4.1/go.mod h1:DdOqcUpL7vgyP4GlF3X3w7HbSlz8cEQzwewPveYEQbA=+github.com/dhui/dktest v0.4.3 h1:wquqUxAFdcUgabAVLvSCOKOlag5cIZuaOjYIBOWdsR0=+github.com/dhui/dktest v0.4.3/go.mod h1:zNK8IwktWzQRm6I/l2Wjp7MakiyaFWv4G1hjmodmMTs=+github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=+github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=-github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=-github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=-github.com/docker/docker v24.0.9+incompatible h1:HPGzNmwfLZWdxHqK9/II92pyi1EpYKsAqcl4G0Of9v0=-github.com/docker/docker v24.0.9+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=-github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=-github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=+github.com/docker/docker v27.2.0+incompatible h1:Rk9nIVdfH3+Vz4cyI/uhbINhEZ/oLmc+CBXmH6fbNk4=+github.com/docker/docker v27.2.0+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=+github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=+github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=-github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=-github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=+github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=+github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=+github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=+github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4 h1:ygs9POGDQpQGLJPlq4+0LBUmMBNox1N4JSpw+OETcvI=github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4=+github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=+github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=+github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=+github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=@@ -35,8 +41,8 @@ github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=-github.com/golang-migrate/migrate/v4 v4.17.1 h1:4zQ6iqL6t6AiItphxJctQb3cFqWiSpMnX7wLTPnnYO4=-github.com/golang-migrate/migrate/v4 v4.17.1/go.mod h1:m8hinFyWBn0SA4QKHuKh175Pm9wjmxj3S2Mia7dbXzM=+github.com/golang-migrate/migrate/v4 v4.18.1 h1:JML/k+t4tpHCpQTCAD62Nu43NUFzHY4CV3uAuvHGC+Y=+github.com/golang-migrate/migrate/v4 v4.18.1/go.mod h1:HAX6m3sQgcdO81tdjn5exv20+3Kb13cmGli1hrD6hks=github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=@@ -64,6 +70,8 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6Tgithub.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=+github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=+github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=@@ -74,8 +82,8 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7Ngithub.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=-github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=-github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=+github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=+github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=github.com/pkoukk/tiktoken-go v0.1.7 h1:qOBHXX4PHtvIvmOtyg1EeKlwFRiMKAcoMp4Q+bLQDmw=@@ -85,40 +93,40 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNgithub.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=-github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po=-github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=-github.com/sashabaranov/go-openai v1.35.6 h1:oi0rwCvyxMxgFALDGnyqFTyCJm6n72OnEG3sybIFR0g=-github.com/sashabaranov/go-openai v1.35.6/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=+github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA=+github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=+github.com/sashabaranov/go-openai v1.35.7 h1:icyrRbkYoKPa4rbO1WSInpJu3qDQrPEnsoJVZ6QymdI=+github.com/sashabaranov/go-openai v1.35.7/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=-github.com/smacker/go-tree-sitter v0.0.0-20240625050157-a31a98a7c0f6 h1:mtD4ESyObQZnRVxHFcaYp2d7jMBDa4WJRXSB1Vszj+A=-github.com/smacker/go-tree-sitter v0.0.0-20240625050157-a31a98a7c0f6/go.mod h1:q99oHDsbP0xRwmn7Vmob8gbSMNyvJ83OauXPSuHQuKE=+github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82 h1:6C8qej6f1bStuePVkLSFxoU22XBS165D3klxlzRg8F4=+github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82/go.mod h1:xe4pgH49k4SsmkQq5OT8abwhWmnzkhpgnXeekbx2efw=github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=-github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=-github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=-github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=-github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=-github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=+github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=+github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=+go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk=+go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8=+go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw=+go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8=+go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc=+go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8=+go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4=+go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ=go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=golang.org/x/image v0.22.0 h1:UtK5yLUzilVrkjMAZAZ34DXGpASN8i8pj8g+O+yd10g=golang.org/x/image v0.22.0/go.mod h1:9hPFhljd4zZ1GNSIZJ49sqbp45GKK9t6w+iXvGqZUz4=-golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=-golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=-golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=-golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=+golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=+golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=-golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=-golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=-golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg=-golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM=+golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=+golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=diff --git a/app/server/handlers/file_maps.go b/app/server/handlers/file_maps.goindex 1eb6e934..a70ddf92 100644--- a/app/server/handlers/file_maps.go+++ b/app/server/handlers/file_maps.go@@ -5,7 +5,7 @@ import ("fmt""log""net/http"- "plandex-server/syntax"+ "plandex-server/syntax/file_map""github.com/plandex/plandex/shared")@@ -19,7 +19,7 @@ func GetFileMapHandler(w http.ResponseWriter, r *http.Request) {maps := make(shared.FileMapBodies)for path, input := range req.MapInputs {- fileMap, err := syntax.MapFile(r.Context(), path, []byte(input))+ fileMap, err := file_map.MapFile(r.Context(), path, []byte(input))if err != nil {// Skip files that can't be parsed, just log the errorlog.Printf("Error mapping file %s: %v", path, err)diff --git a/app/server/model/plan/build_exec.go b/app/server/model/plan/build_exec.goindex cef5622b..ef024a2c 100644--- a/app/server/model/plan/build_exec.go+++ b/app/server/model/plan/build_exec.go@@ -8,7 +8,6 @@ import ("plandex-server/hooks""plandex-server/model""plandex-server/model/prompts"- "plandex-server/syntax""plandex-server/types""github.com/davecgh/go-spew/spew"@@ -240,25 +239,25 @@ func (fileState *activeBuildStreamFileState) buildFile() {})// validate syntax of new file- validationRes, err := syntax.Validate(activePlan.Ctx, filePath, activeBuild.FileContent)+ // validationRes, err := syntax.Validate(activePlan.Ctx, filePath, activeBuild.FileContent)- if err != nil {- log.Printf("Error validating syntax for new file '%s': %v\n", filePath, err)- fileState.onBuildFileError(fmt.Errorf("error validating syntax for new file '%s': %v", filePath, err))- return- }+ // if err != nil {+ // log.Printf("Error validating syntax for new file '%s': %v\n", filePath, err)+ // fileState.onBuildFileError(fmt.Errorf("error validating syntax for new file '%s': %v", filePath, err))+ // return+ // }// new fileplanRes := &db.PlanFileResult{- OrgId: currentOrgId,- PlanId: planId,- PlanBuildId: build.Id,- ConvoMessageId: build.ConvoMessageId,- Path: filePath,- Content: activeBuild.FileContent,- WillCheckSyntax: validationRes.HasParser && !validationRes.TimedOut,- SyntaxValid: validationRes.Valid,- SyntaxErrors: validationRes.Errors,+ OrgId: currentOrgId,+ PlanId: planId,+ PlanBuildId: build.Id,+ ConvoMessageId: build.ConvoMessageId,+ Path: filePath,+ Content: activeBuild.FileContent,+ // WillCheckSyntax: validationRes.HasParser && !validationRes.TimedOut,+ // SyntaxValid: validationRes.Valid,+ // SyntaxErrors: validationRes.Errors,}log.Println("build exec - Plan file result:")diff --git a/app/server/model/plan/build_structured_edits.go b/app/server/model/plan/build_structured_edits.goindex 1394f736..a1cc72b8 100644--- a/app/server/model/plan/build_structured_edits.go+++ b/app/server/model/plan/build_structured_edits.go@@ -11,6 +11,7 @@ import ("plandex-server/model/prompts""plandex-server/syntax""plandex-server/types"+ "slices""strings""time"@@ -44,12 +45,36 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {return}- proposedContentLines := strings.Split(activeBuild.FileContent, "\n")+ proposedContent := activeBuild.FileContent+ proposedContentLines := strings.Split(proposedContent, "\n")originalContentLines := strings.Split(originalFile, "\n")+ var references []syntax.Reference+ var removals []syntax.Removal++ for i, line := range proposedContentLines {+ content := strings.TrimSpace(line)++ found := false++ if strings.Contains(strings.ToLower(content), "... existing code ...") {+ references = append(references, syntax.Reference(i+1))+ found = true+ } else if strings.Contains(strings.ToLower(content), "plandex: removed code") {+ removals = append(removals, syntax.Removal(i+1))+ found = true+ }++ if found {+ proposedContentLines[i] = strings.Replace(proposedContentLines[i], content, "", 1)+ }+ }++ proposedContent = strings.Join(proposedContentLines, "\n")+log.Println("buildStructuredEdits - getting references prompt")- anchorsSysPrompt := prompts.GetSemanticAnchorsPrompt(filePath, originalFile, activeBuild.FileContent, activeBuild.FileDescription)+ anchorsSysPrompt := prompts.GetSemanticAnchorsPrompt(filePath, originalFile, proposedContent, activeBuild.FileDescription)anchorsFileMessages := []openai.ChatCompletionMessage{{@@ -197,27 +222,76 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {}}- fileContent := activeBuild.FileContent- fileContentLines := strings.Split(fileContent, "\n")+ refsXmlString, err := GetXMLTag(content, "PlandexReferences")+ if err != nil {+ log.Printf("buildStructuredEdits - error parsing PlandexReferences xml: %v\n", err)+ }- var references []syntax.Reference- var removals []syntax.Removal+ var refsElement types.ReferencesTag+ if refsXmlString != "" {+ err = xml.Unmarshal([]byte(refsXmlString), &refsElement)+ if err != nil {+ log.Printf("buildStructuredEdits - error unmarshalling PlandexReferences xml: %v\n", err)+ fileState.structuredEditRetryOrError(fmt.Errorf("error unmarshalling PlandexReferences xml: %v", err))+ return+ }++ for _, ref := range refsElement.References {+ proposedLine, err := shared.ExtractLineNumberWithPrefix(ref.ProposedLine, "pdx-new-")+ if err != nil {+ log.Printf("buildStructuredEdits - error parsing anchor proposed line num: %v\n", err)+ fileState.structuredEditRetryOrError(fmt.Errorf("error parsing anchor proposed line num: %v", err))+ return+ }++ references = append(references, syntax.Reference(proposedLine))+ }+ }++ removalsXmlString, err := GetXMLTag(content, "PlandexRemovals")+ if err != nil {+ log.Printf("buildStructuredEdits - error parsing PlandexRemovals xml: %v\n", err)+ }+ var removalsElement types.RemovalsTag+ if removalsXmlString != "" {+ err = xml.Unmarshal([]byte(removalsXmlString), &removalsElement)+ if err != nil {+ log.Printf("buildStructuredEdits - error unmarshalling PlandexRemovals xml: %v\n", err)+ }++ for _, removal := range removalsElement.Removals {+ proposedLine, err := shared.ExtractLineNumberWithPrefix(removal.ProposedLine, "pdx-new-")+ if err != nil {+ log.Printf("buildStructuredEdits - error parsing anchor proposed line num: %v\n", err)+ }++ removals = append(removals, syntax.Removal(proposedLine))+ }+ }++ slices.Sort(references)+ slices.Sort(removals)++ hasRefByLine := make(map[int]bool)+ for _, ref := range references {+ hasRefByLine[int(ref)] = true+ }+ for _, rev := range removals {+ hasRefByLine[int(rev)] = true+ }var beginsWithRef bool = falsevar endsWithRef bool = falsevar foundNonRefLine bool = false- for i, line := range fileContentLines {- line = strings.ToLower(strings.TrimSpace(line))+ for i, line := range proposedContentLines {+ hasRef := hasRefByLine[i+1]- if strings.Contains(line, "... existing code ...") {- references = append(references, syntax.Reference(i+1))+ if hasRef {if !foundNonRefLine {beginsWithRef = true}endsWithRef = true- } else if strings.Contains(line, "plandex: removed code") {- removals = append(removals, syntax.Removal(i+1))} else if line != "" {foundNonRefLine = trueendsWithRef = false@@ -229,7 +303,7 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {!strings.Contains(activeBuild.FileDescription, "the start of the file") {// structured edits handle normalization of comments, so just use // ... existing code ... here- fileContentLines = append([]string{"// ... existing code ..."}, fileContentLines...)+ proposedContentLines = append([]string{"// ... existing code ..."}, proposedContentLines...)// bump all existing references up by 1for i, ref := range references {@@ -241,18 +315,18 @@ func (fileState *activeBuildStreamFileState) buildStructuredEdits() {if !endsWithRef &&!strings.Contains(activeBuild.FileDescription, "overwrite the entire file") &&!strings.Contains(activeBuild.FileDescription, "the end of the file") {- fileContentLines = append(fileContentLines, "// ... existing code ...")- references = append(references, syntax.Reference(len(fileContentLines)))+ proposedContentLines = append(proposedContentLines, "// ... existing code ...")+ references = append(references, syntax.Reference(len(proposedContentLines)))}- fileContent = strings.Join(fileContentLines, "\n")+ proposedContent = strings.Join(proposedContentLines, "\n")updatedFile, err := syntax.ApplyChanges(activePlan.Ctx,fileState.language,parser,originalFile,- fileContent,+ proposedContent,references,removals,anchorLines,diff --git a/app/server/model/plan/tell_stream.go b/app/server/model/plan/tell_stream.goindex 35f2c1da..47120a22 100644--- a/app/server/model/plan/tell_stream.go+++ b/app/server/model/plan/tell_stream.go@@ -51,6 +51,7 @@ func (state *activeTellStreamState) listenStream(stream *openai.ChatCompletionStreplyFiles := []string{}chunksReceived := 0maybeRedundantBacktickContent := ""+ fileOpen := false// Create a timer that will trigger if no chunk is received within the specified durationtimer := time.NewTimer(model.OPENAI_STREAM_CHUNK_TIMEOUT)@@ -185,6 +186,7 @@ mainLoop:if choice.FinishReason != "" {log.Println("Model stream finished")+ // spew.Dump(choice)active.FlushStreamBuffer()time.Sleep(100 * time.Millisecond)@@ -456,6 +458,8 @@ mainLoop:time.Sleep(50 * time.Millisecond)+ // note: tell-based verification is currently disabled, so 'verifyOrFinish' will pass through to 'finish' logic+ // ShouldVerifyDiff will always be false unless we re-enable tell-based verificationif buildFinished {log.Println("Reply is finished and build is finished, calling verifyOrFinish")state.verifyOrFinish()@@ -500,6 +504,8 @@ mainLoop:delta := choice.Deltacontent := delta.Content+ // log.Printf("content: %s\n", content)+if missingFileResponse != "" {if maybeRedundantBacktickContent != "" {if strings.Contains(content, "\n") {@@ -517,8 +523,24 @@ mainLoop:}}+ // log.Printf("Adding chunk to parser: %s\n", content)+replyParser.AddChunk(content, true)parserRes := replyParser.Read()++ if !fileOpen && parserRes.CurrentFilePath != "" {+ fileOpen = true+ }++ if fileOpen && strings.HasSuffix(content, "```") {+ log.Println("FinishAndRead because of closing backticks")+ parserRes = replyParser.FinishAndRead()+ }++ if fileOpen && parserRes.CurrentFilePath == "" {+ fileOpen = false+ }+files := parserRes.FilesfileContents := parserRes.FileContentsstate.replyNumTokens = parserRes.TotalTokensdiff --git a/app/server/model/prompts/build_update.go b/app/server/model/prompts/build_update.goindex 84bbece6..9dbeff9a 100644--- a/app/server/model/prompts/build_update.go+++ b/app/server/model/prompts/build_update.go@@ -42,7 +42,11 @@ func GetWholeFilePrompt(filePath, preBuildState, changesFile, changesDesc string}var SemanticAnchorsPrompt = `-You are an AI that analyzes an *original file* and *proposed updates* to that file and then identifies *semantic anchors* present in the *proposed updates*.+You are an AI that analyzes an *original file* and *proposed updates* to that file and then identifies all *semantic anchors* and *reference comments* present in the *proposed updates*.++-++### Semantic AnchorsA semantic anchor is a line in the *proposed updates* that is not exactly equal to a line in the *original file* but is nonetheless intended to match a line in the *original file*.@@ -71,8 +75,6 @@ The line 'pdx-new-6: }' is *not* a semantic anchor since it is exactly equal toComments that are modified in the *proposed updates* (but are clearly still referring to the same comment in the *original file*) can also be semantic anchors.-Comments that take the form of "// ... existing code ..." (or the equivalent in other languages) are *NOT* semantic anchors. You MUST NEVER WITHOUT EXCEPTION mark comments that take this form as semantic anchors.-A line that is exactly equal (including whitespace) to a line in the *original file* MUST NEVER UNDER ANY CONCEIVABLE CIRCUMSTANCES be marked as a semantic anchor.For example, if the *original file* has:@@ -100,15 +102,126 @@ If a line in the *proposed updates* is identical to a line in the *original fileIf a line in the *proposed updates* is a semantic anchor and there is a comment (or multiple comments) associated with the line that is being modified, carefully consider if the comment should also be marked as a semantic anchor. If the comment or comments clearly map to a corresponding comment in the *original file*, and the comment is modified in the *proposed updates*, then it MUST be marked as a semantic anchor. Correctly marking comments as sematic anchors is just as important as marking other lines of code as semantic anchors.-First, output a single *brief* paragraph of general reasoning about the *proposed updates* and how they refer to the *original file*, focusing on the structure of each, which elements are changing, and how the changes map to the *original file*. Also make a brief note of any comments that are being modified or introduced in the *proposed updates* and whether/how they map to comments in the *original file*. Do NOT output a list of semantic anchors in this paragraph—save that for the next section.+-++### Reference Comments++A reference comment is a comment that references code in the *original file* for the purpose of making it clear where a change should be applied. Examples of reference comments include:++ - // ... existing code...+ - # Existing code...+ - /* ... */+ - // Rest of the function...+ - <!-- rest of div tag -->+ - // ... rest of function ...+ - // rest of component...+ - # other methods...+ - // ... rest of init code...+ - // rest of the class...+ - // other properties+ - // other methods+ // ... existing properties ...+ // ... existing values ...+ // ... existing text ...++Reference comments often won't exactly match one of the above examples, but they will always be referencing a block of code from the *original file* that is left out of the *proposed updates* for the sake of focusing on the specific change that is being made.++For some file types that don't use comments like JSON or plain text, reference comments in the form of '// ... existing properties ...' or '// ... existing values ...' or '// ... existing text ...' can still be present. These MUST be treated as valid reference comments regardless of the validity of the comment syntax.++-++### Removal Comments++A removal comment is a comment that indicates that a section of code should be removed from the *original file*. Examples of removal comments include:-Next, output a <PlandexSummary> element that gives a very brief, one-sentence summary of the changes being made. Example:+ - // removed code+ - # removed start of function+ - <!-- removed 'container' div -->+ - // remove 'checkMigration' method++Removal comments often won't exactly match one of the above examples, but they will always be indicating that a section of code should be removed from the *original file*.++For some file types that don't use comments like JSON or plain text, removal comments like '// removed keys ...' can still be present. These MUST be treated as valid removal comments regardless of the validity of the comment syntax.++-++### Output++**First,** output a single *brief* paragraph of general reasoning about the *proposed updates* and how they refer to the *original file*, focusing on the structure of each, which elements are changing, and how the changes map to the *original file*. Also make a brief note of any comments that are being modified or introduced in the *proposed updates* and whether/how they map to comments in the *original file*. Do NOT output a list of semantic anchors in this paragraph—save that for the next section.++**Next,** output a <PlandexSummary> element that gives a very brief, one-sentence summary of the changes being made. Example:<PlandexSummary>Adds a 'log' parameter to the 'update' function and modifies the 'update' function to use it.</PlandexSummary>-Last, output xml with this structure:+**Next,** output a section that lists *EVERY* comment in the *proposed updates*, including the line number of each comment prefixed by 'pdx-new-'. Below each comment, evaluate whether it is a *reference comment*, a *removal comment*, or neither.++*To determined whether a comment is a reference comment*, focus on whether the comment is clearly referencing a block of code in the *original file*, whether it is explaining a change being made, or whether it is a comment that was carried over from the *original file* but does *not* reference any code that was left out of the *proposed updates*.++*To determine whether a comment is a removal comment*, focus on whether the comment is clearly indicating that a section of code should be removed from the *original file*.++After this evaluation, state whether each comment is a *reference comment*, a *removal comment*, or neither. Only list valid *comments* for the given programming language in the comments section. Do not include non-comment lines of code in the comments section. The only exception to this rule is for file types that don't use comments like JSON or plain text—for these treat lines beginning with '//' as reference comments. A *removal comment* *MUST NOT* also be marked as a *reference comment* and a *reference comment* *MUST NOT* also be marked as a *removal comment*.++Reference comments example:++---+Comments:++pdx-new-2: // ... existing code to start transaction ...+Evaluation: refers the code at the beginning of the 'update' function that starts the database transaction.+Reference: true+Removal: false++pdx-new-6: // ... existing update code ...+Evaluation: refers the code inside the 'update' function that updates the user.+Reference: true+Removal: false++pdx-new-9: // Removed 'checkMigration' method+Evaluation: refers the 'checkMigration' method that is being removed.+Reference: false+Removal: true++pdx-new-15: // verify user permission before performing update+Evaluation: describes the change being made. Does not refer to any code in the *original file*.+Reference: false+Removal: false++pdx-new-85: // Rest of the main function...+Evaluation: refers to the rest of the main function that is left unchanged.+Reference: true+Removal: false++pdx-new-25: # removed rest of init code+Evaluation: indicates that the rest of the init code should be removed from the *original file*.+Reference: false+Removal: true+---++**Next,** for each reference (if there are any), output valid xml with this structure:++<PlandexReferences>+ <Reference+ comment="// ... rest of function ..."+ proposedLine="pdx-new-10"+ />+</PlandexReferences>++If there are no reference comments, output an empty <PlandexReferences> element.++**Next,** for each removal (if there are any), output valid xml with this structure:++<PlandexRemovals>+ <Removal+ comment="# removed rest of init code"+ proposedLine="pdx-new-25"+ />+</PlandexRemovals>++If there are no removal comments, output an empty <PlandexRemovals> element.++**Last,** output xml with this structure:<PlandexSemanticAnchors><Anchor@@ -128,6 +241,8 @@ Explanation of 'Anchor' tag attributes:If there are no semantic anchors, output an empty <PlandexSemanticAnchors> element. Do NOT invent semantic anchors if there are none. It's common for there to be no semantic anchors in the *proposed updates*. In that case, output an empty <PlandexSemanticAnchors> element.+A *reference comment* or *removal comment* *MUST NOT* also be marked a semantic anchor. You MUST NEVER WITHOUT EXCEPTION mark *reference comments* or *removal comments* as semantic anchors.+Every response must include a single <PlandexSummary> element and a single <PlandexSemanticAnchors> element.Do NOT include any other text or comments in your output.diff --git a/app/server/syntax/file_map.go b/app/server/syntax/file_map.godeleted file mode 100644index 4d59885c..00000000--- a/app/server/syntax/file_map.go+++ /dev/null@@ -1,586 +0,0 @@-package syntax--import (- "context"- "fmt"- "path/filepath"- "strings"-- "github.com/plandex/plandex/shared"- tree_sitter "github.com/smacker/go-tree-sitter"-)--// FileMap represents a file's important definitions-type FileMap struct {- Definitions []Definition-}--type Definition struct {- Type string // "function", "class", "key", "selector", "instruction" etc- Signature string // The full signature/header without implementation- Comments []string // Any comments that precede this definition- TagAttrs []string // For xml style markup tags, the class and id attributes- Line int // Line number where definition starts- Children []Definition // For parent types that can contain nested definitions-}--func MapFile(ctx context.Context, filename string, content []byte) (*FileMap, error) {- // Get appropriate parser- ext := filepath.Ext(filename)- parser, lang, _, _ := GetParserForExt(ext)- if parser == nil {- return nil, fmt.Errorf("unsupported file type: %s", ext)- }-- // Parse file- tree, err := parser.ParseCtx(ctx, nil, content)- if err != nil {- return nil, fmt.Errorf("failed to parse file: %v", err)- }- defer tree.Close()-- // Create map- m := &FileMap{- Definitions: mapNode(tree.RootNode(), content, lang),- }- return m, nil-}--func mapNode(node *tree_sitter.Node, content []byte, lang shared.TreeSitterLanguage) []Definition {- switch lang {- case shared.TreeSitterLanguageDockerfile:- return mapDockerfile(node, content)- case shared.TreeSitterLanguageYaml, shared.TreeSitterLanguageToml, shared.TreeSitterLanguageJson, shared.TreeSitterLanguageCue, shared.TreeSitterLanguageHcl:- return mapConfig(node, content)- case shared.TreeSitterLanguageHtml, shared.TreeSitterLanguageSvelte:- return mapMarkup(node, content)- case shared.TreeSitterLanguageCss:- return mapCSS(node, content)- default:- return mapTraditional(node, content)- }-}--// For traditional programming languages-func mapTraditional(node *tree_sitter.Node, content []byte) []Definition {- var defs []Definition- cursor := tree_sitter.NewTreeCursor(node)- defer cursor.Close()-- if cursor.GoToFirstChild() {- for {- node := cursor.CurrentNode()- nodeType := node.Type()-- if verboseLogging {- fmt.Println()- fmt.Println("node", nodeType)- fmt.Println("content", string(node.Content(content)))- fmt.Println()- }-- // Check if this is a definition node- if isDefinitionNode(nodeType) {- if verboseLogging {- fmt.Println("definition node", nodeType)- }-- def := Definition{- Type: nodeType,- Line: int(node.StartPoint().Row) + 1,- }-- if isAssignmentNode(nodeType) {- if verboseLogging {- fmt.Println("assignment node", node.Content(content))- }- // Try different field names for identifiers- // fmt.Printf("assignment node: %s\n", nodeType)- sig := ""-- assignmentBoundary := findAssignmentBoundary(node)-- if assignmentBoundary != nil {- start := node.StartByte()- end := assignmentBoundary.StartByte()- sig = string(content[start:end])- sig = strings.TrimSuffix(strings.TrimSpace(sig), "=")- } else {- identifiers := findIdentifier(node)- if len(identifiers) > 0 {- if verboseLogging {- fmt.Println("found identifiers", len(identifiers))- }-- start := node.StartByte()- end := identifiers[len(identifiers)-1].EndByte()- sig = string(content[start:end])- } else {- if verboseLogging {- fmt.Println("no identifier found", nodeType)- }- sig = string(node.Content(content)) + " "- }- }-- def.Signature = sig- } else {- if verboseLogging {- fmt.Println("not assignment node", nodeType)- }- // Get signature (up to body)-- if body := findImplementationBoundary(node); body != nil {- start := node.StartByte()- var end uint32- if node == body {- if verboseLogging {- fmt.Println("node == body")- }- firstChild := firstDefinitionChild(body)- if firstChild != nil {- if verboseLogging {- fmt.Println("firstChild != nil")- fmt.Println("firstChild", firstChild.Type())- fmt.Println("firstChild content", string(firstChild.Content(content)))- }- end = firstChild.StartByte()- } else {- if verboseLogging {- fmt.Println("firstChild == nil")- }- end = body.EndByte()- }- } else {- end = body.StartByte()- }- if verboseLogging {- fmt.Println("start", start)- fmt.Println("end", end)- }- def.Signature = string(content[start:end])- if verboseLogging {- fmt.Println("got signature", def.Signature)- }-- // If this is a parent type node, recurse into the body- if isParentNode(nodeType) {- if verboseLogging {- fmt.Println("recursing into body", nodeType)- }- def.Children = mapTraditional(body, content)- }- } else {- if verboseLogging {- fmt.Println("no body found", nodeType)- }- def.Signature = string(node.Content(content))- }- }-- // Get preceding comments- def.Comments = getPrecedingComments(node, content)-- defs = append(defs, def)- }-- if !cursor.GoToNextSibling() {- break- }- }- }-- return defs-}--// Helper functions for definitions and parents-func isDefinitionNode(nodeType string) bool {- // Ignore import/require/use/include and similar nodes- if strings.HasPrefix(nodeType, "import_") ||- strings.HasPrefix(nodeType, "require_") ||- strings.HasPrefix(nodeType, "use_") ||- strings.HasPrefix(nodeType, "using_") ||- strings.HasPrefix(nodeType, "include_") ||- strings.HasPrefix(nodeType, "package_") ||- strings.HasPrefix(nodeType, "module_") {- return false- }-- if isAssignmentNode(nodeType) ||-- strings.HasSuffix(nodeType, "_definition") ||- strings.HasSuffix(nodeType, "_declaration") ||- strings.HasSuffix(nodeType, "_declarator") ||- strings.HasSuffix(nodeType, "_spec") ||- strings.HasSuffix(nodeType, "_binding") ||- strings.HasSuffix(nodeType, "_signature") {-- return true- }- return false-}--var parentNodeTypes = map[string]bool{- "namespace_definition": true, // C++- "namespace_declaration": true, // C#- "module_definition": true, // Ruby- "class_definition": true, // Python/Ruby- "class_declaration": true, // Java/C#/TypeScript- // "interface_declaration": true, // Java/TypeScript- // "trait_definition": true, // Rust- // "trait_declaration": true, // PHP- "impl_block": true, // Rust implementations- // "type_declaration": true, // Go- "const_declaration": true, // Go-}--func isParentNode(nodeType string) bool {- return parentNodeTypes[nodeType]-}--var assignmentNodeTypes = map[string]bool{- // Common patterns- "assignment_expression": true,- "declaration": true,- "variable_declaration": true,-- // Go- "const_spec": true,- "var_declaration": true,-- // JS/TS- "lexical_declaration": true,-- // Python- "assignment_statement": true,-- // Ruby- "variable_assignment": true,- "class_variable_assignment": true,-- // Rust- "let_declaration": true,- "const_item": true,-- // Java, C#- "static_declaration": true,- "member_declaration": true,- "field_declaration": true,-- // Kotlin/Scala- "property_declaration": true,-- // OCaml- "let_binding": true,- "value_binding": true,-- // Elixir- "module_attribute": true,-- // PHP- "global_declaration": true,- "static_variable_declaration": true,-}--func isAssignmentNode(nodeType string) bool {- return assignmentNodeTypes[nodeType]-}--// Implementation boundary detection-var implBodyNodeTypes = map[string]bool{- "block": true,- "body": true,- "suite": true,- "statement_block": true,- "compound_statement": true,- "function_body": true,- "do_block": true,- "implementation": true,- "field_declaration_list": true, // Go- "const_declaration": true, // Go- "method_elem": true,-}--var assignmentBodyNodeTypes = map[string]bool{- "literal_value": true,- "expression_list": true,-}--func findImplementationBoundary(node *tree_sitter.Node) *tree_sitter.Node {- if implBodyNodeTypes[node.Type()] {- return node- }-- for i := 0; i < int(node.ChildCount()); i++ {- child := node.Child(i)-- if implBodyNodeTypes[child.Type()] {- return child- } else {- found := findImplementationBoundary(child)- if found != nil {- return found- }- }- }- return nil-}--func findIdentifier(node *tree_sitter.Node) []*tree_sitter.Node {- t := node.Type()- if t == "identifier" || strings.HasSuffix(t, "_identifier") {- return []*tree_sitter.Node{node}- }-- nodes := []*tree_sitter.Node{}- for i := 0; i < int(node.ChildCount()); i++ {- child := node.Child(i)- found := findIdentifier(child)- if found != nil {- nodes = append(nodes, found...)- }- }- return nodes-}--func firstDefinitionChild(node *tree_sitter.Node) *tree_sitter.Node {- for i := 0; i < int(node.ChildCount()); i++ {- child := node.Child(i)- if isDefinitionNode(child.Type()) {- return child- }- }- return nil-}--func findAssignmentBoundary(node *tree_sitter.Node) *tree_sitter.Node {- if assignmentBodyNodeTypes[node.Type()] {- return node- }-- for i := 0; i < int(node.ChildCount()); i++ {- child := node.Child(i)- found := findAssignmentBoundary(child)- if found != nil {- return found- }- }- return nil-}--// Get preceding comments-func getPrecedingComments(node *tree_sitter.Node, content []byte) []string {- var comments []string- const maxCommentLength = 1000-- prevNode := node.PrevSibling()- for prevNode != nil {- if !strings.Contains(prevNode.Type(), "comment") {- break- }- comment := string(prevNode.Content(content))- if len(comment) > maxCommentLength {- comment = comment[:maxCommentLength] + "..."- }- comments = append([]string{comment}, comments...)- prevNode = prevNode.PrevSibling()- }- return comments-}--// Specialized mappers-func mapConfig(node *tree_sitter.Node, content []byte) []Definition {- cursor := tree_sitter.NewTreeCursor(node)- defer cursor.Close()-- var walkConfig func(*tree_sitter.Node) []Definition- walkConfig = func(node *tree_sitter.Node) []Definition {- var nodeDefs []Definition-- if node.Type() == "pair" || // YAML- node.Type() == "key_value" || // TOML- node.Type() == "field" { // CUE/HCL- if keyNode := node.ChildByFieldName("key"); keyNode != nil {- def := Definition{- Type: "key",- Signature: string(keyNode.Content(content)),- Line: int(keyNode.StartPoint().Row) + 1,- }-- // Check for block values to find nested keys- if valNode := node.ChildByFieldName("value"); valNode != nil {- if valNode.Type() == "block_mapping" || // YAML- valNode.Type() == "block" { // TOML/HCL/CUE- def.Children = walkConfig(valNode)- }- }-- nodeDefs = append(nodeDefs, def)- }- }-- // Walk siblings- for i := 0; i < int(node.ChildCount()); i++ {- nodeDefs = append(nodeDefs, walkConfig(node.Child(i))...)- }-- return nodeDefs- }-- return walkConfig(node)-}--func mapMarkup(node *tree_sitter.Node, content []byte) []Definition {- cursor := tree_sitter.NewTreeCursor(node)- defer cursor.Close()-- var walkMarkup func(*tree_sitter.Node) []Definition- walkMarkup = func(node *tree_sitter.Node) []Definition {- var nodeDefs []Definition-- if node.Type() == "start_tag" || node.Type() == "self_closing_tag" {- // Get tag name- nameNode := node.ChildByFieldName("name")- if nameNode == nil {- return nodeDefs- }-- // Get class and id attributes only- var attrs []string- for i := 0; i < int(node.ChildCount()); i++ {- child := node.Child(i)- if child.Type() == "attribute" {- attrName := child.ChildByFieldName("name")- if attrName != nil {- name := string(attrName.Content(content))- if name == "class" || name == "id" {- attrVal := child.ChildByFieldName("value")- if attrVal != nil {- attrs = append(attrs, fmt.Sprintf("%s=%q",- name, attrVal.Content(content)))- }- }- }- }- }-- def := Definition{- Type: "tag",- Line: int(node.StartPoint().Row) + 1,- Signature: string(nameNode.Content(content)),- TagAttrs: attrs,- }-- // Recursively process children- for i := 0; i < int(node.ChildCount()); i++ {- child := node.Child(i)- def.Children = append(def.Children, walkMarkup(child)...)- }-- nodeDefs = append(nodeDefs, def)- }-- return nodeDefs- }-- return walkMarkup(node)-}--func mapCSS(node *tree_sitter.Node, content []byte) []Definition {- var defs []Definition- cursor := tree_sitter.NewTreeCursor(node)- defer cursor.Close()-- if cursor.GoToFirstChild() {- for {- node := cursor.CurrentNode()- if node.Type() == "selector" {- defs = append(defs, Definition{- Type: "selector",- Signature: string(node.Content(content)),- Line: int(node.StartPoint().Row) + 1,- })- }- if !cursor.GoToNextSibling() {- break- }- }- }- return defs-}--var dockerKeyInstructions = map[string]bool{- "FROM": true,- "ENTRYPOINT": true,- "CMD": true,- "EXPOSE": true,- "COPY": true,- "ENV": true,-}--func mapDockerfile(node *tree_sitter.Node, content []byte) []Definition {- var defs []Definition- cursor := tree_sitter.NewTreeCursor(node)- defer cursor.Close()-- if cursor.GoToFirstChild() {- for {- node := cursor.CurrentNode()- if node.Type() == "instruction" {- instruction := string(node.Content(content))- command := strings.Fields(instruction)[0]- if dockerKeyInstructions[command] {- defs = append(defs, Definition{- Type: "instruction",- Signature: instruction,- Line: int(node.StartPoint().Row) + 1,- })- }- }- if !cursor.GoToNextSibling() {- break- }- }- }- return defs-}--func (m *FileMap) String() string {- var b strings.Builder-- var writeDefinition func(def *Definition, depth int)- writeDefinition = func(def *Definition, depth int) {- // Indent- if depth > 0 {- b.WriteString(strings.Repeat(" ", depth))- b.WriteString("- ")- }-- // Write signature (for tags, include attrs)- if def.Type == "tag" {- // Extract tag name from signature (it's the first word)- tagName := strings.Fields(def.Signature)[0]- // Build full representation with attrs- if len(def.TagAttrs) > 0 {- b.WriteString(fmt.Sprintf("%s %s", tagName, strings.Join(def.TagAttrs, " ")))- } else {- b.WriteString(tagName)- }- } else {- b.WriteString(strings.TrimSpace(def.Signature))- }- b.WriteString("\n")-- // Write children with increased depth- for _, child := range def.Children {- writeDefinition(&child, depth+1)- }- }-- // Write all top-level definitions- for _, def := range m.Definitions {- writeDefinition(&def, 0)- }-- return b.String()-}diff --git a/app/server/syntax/map_cli/.gitignore b/app/server/syntax/file_map/cli/.gitignoresimilarity index 100%rename from app/server/syntax/map_cli/.gitignorerename to app/server/syntax/file_map/cli/.gitignorediff --git a/app/server/syntax/map_cli/go.mod b/app/server/syntax/file_map/cli/go.modsimilarity index 85%rename from app/server/syntax/map_cli/go.modrename to app/server/syntax/file_map/cli/go.modindex 656bfed7..a414b47f 100644--- a/app/server/syntax/map_cli/go.mod+++ b/app/server/syntax/file_map/cli/go.mod@@ -2,11 +2,11 @@ module mappergo 1.23.3-replace plandex-server => ../../+replace plandex-server => ../../../-replace github.com/plandex/plandex/shared => ../../../shared+replace github.com/plandex/plandex/shared => ../../../../shared-replace plandex => ../../../cli+replace plandex => ../../../../clirequire (github.com/plandex/plandex/shared v0.0.0-00010101000000-000000000000@@ -33,7 +33,7 @@ require (github.com/davecgh/go-spew v1.1.1 // indirectgithub.com/dlclark/regexp2 v1.11.4 // indirectgithub.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 // indirect- github.com/fatih/color v1.17.0 // indirect+ github.com/fatih/color v1.18.0 // indirectgithub.com/google/uuid v1.6.0 // indirectgithub.com/gorilla/css v1.0.1 // indirectgithub.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect@@ -54,15 +54,15 @@ require (github.com/plandex-ai/survey/v2 v2.3.7 // indirectgithub.com/rivo/uniseg v0.4.7 // indirectgithub.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect- github.com/sashabaranov/go-openai v1.35.6 // indirect+ github.com/sashabaranov/go-openai v1.35.7 // indirectgithub.com/shopspring/decimal v1.4.0 // indirect- github.com/smacker/go-tree-sitter v0.0.0-20240625050157-a31a98a7c0f6 // indirect+ github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82 // indirectgithub.com/yuin/goldmark v1.6.0 // indirectgithub.com/yuin/goldmark-emoji v1.0.2 // indirectgolang.org/x/image v0.22.0 // indirect- golang.org/x/net v0.18.0 // indirect+ golang.org/x/net v0.31.0 // indirectgolang.org/x/sync v0.9.0 // indirect- golang.org/x/sys v0.24.0 // indirect- golang.org/x/term v0.19.0 // indirect+ golang.org/x/sys v0.27.0 // indirect+ golang.org/x/term v0.26.0 // indirectgolang.org/x/text v0.20.0 // indirect)diff --git a/app/server/syntax/map_cli/go.sum b/app/server/syntax/file_map/cli/go.sumsimilarity index 99%rename from app/server/syntax/map_cli/go.sumrename to app/server/syntax/file_map/cli/go.sumindex 0a893698..f01e3722 100644--- a/app/server/syntax/map_cli/go.sum+++ b/app/server/syntax/file_map/cli/go.sum@@ -305,8 +305,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=-github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=-github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=+github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=+github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=@@ -633,8 +633,8 @@ github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjgithub.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=github.com/sagikazarmark/crypt v0.8.0/go.mod h1:TmKwZAo97S4Fy4sfMH/HX/cQP5D+ijra2NyLpNNmttY=github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=-github.com/sashabaranov/go-openai v1.35.6 h1:oi0rwCvyxMxgFALDGnyqFTyCJm6n72OnEG3sybIFR0g=-github.com/sashabaranov/go-openai v1.35.6/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=+github.com/sashabaranov/go-openai v1.35.7 h1:icyrRbkYoKPa4rbO1WSInpJu3qDQrPEnsoJVZ6QymdI=+github.com/sashabaranov/go-openai v1.35.7/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE=github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=@@ -643,8 +643,8 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVgithub.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=-github.com/smacker/go-tree-sitter v0.0.0-20240625050157-a31a98a7c0f6 h1:mtD4ESyObQZnRVxHFcaYp2d7jMBDa4WJRXSB1Vszj+A=-github.com/smacker/go-tree-sitter v0.0.0-20240625050157-a31a98a7c0f6/go.mod h1:q99oHDsbP0xRwmn7Vmob8gbSMNyvJ83OauXPSuHQuKE=+github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82 h1:6C8qej6f1bStuePVkLSFxoU22XBS165D3klxlzRg8F4=+github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82/go.mod h1:xe4pgH49k4SsmkQq5OT8abwhWmnzkhpgnXeekbx2efw=github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=@@ -670,12 +670,11 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=-github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=-github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=-github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=+github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=+github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=@@ -831,8 +830,8 @@ golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSgolang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=-golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=-golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=+golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=+golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=@@ -967,14 +966,14 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=-golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=-golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=+golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=+golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=-golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=-golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=+golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=+golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=diff --git a/app/server/syntax/map_cli/main.go b/app/server/syntax/file_map/cli/main.gosimilarity index 58%rename from app/server/syntax/map_cli/main.gorename to app/server/syntax/file_map/cli/main.goindex b0629abe..0dce531d 100644--- a/app/server/syntax/map_cli/main.go+++ b/app/server/syntax/file_map/cli/main.go@@ -4,8 +4,7 @@ import ("context""fmt""os"- "path/filepath"- "plandex-server/syntax"+ "plandex-server/syntax/file_map""plandex/lib""plandex/types""sync"@@ -18,14 +17,24 @@ func main() {ctx, cancel := context.WithTimeout(context.Background(), time.Minute)defer cancel()- if len(os.Args) < 2 {+ args := os.Args[1:]++ if len(args) < 1 {fmt.Println("usage: mapper [files-or-dirs...]")os.Exit(1)}- inputPaths := os.Args[1:]+ var parserTree bool = false++ for i, arg := range args {+ if arg == "--trees" {+ parserTree = true+ args = append(args[:i], args[i+1:]...)+ break+ }+ }- flattenedPaths, err := lib.ParseInputPaths(inputPaths, &types.LoadContextParams{+ flattenedPaths, err := lib.ParseInputPaths(args, &types.LoadContextParams{DefsOnly: true,})@@ -36,7 +45,7 @@ func main() {var filteredPaths []stringfor _, path := range flattenedPaths {- if shared.IsTreeSitterExtension(filepath.Ext(path)) {+ if shared.HasFileMapSupport(path) {filteredPaths = append(filteredPaths, path)}}@@ -67,11 +76,20 @@ func main() {}}- mapBodies, err := syntax.ProcessMapFiles(ctx, fileInputs)- if err != nil {- fmt.Printf("error processing map files: %v\n", err)- os.Exit(1)- }+ if parserTree {+ trees, err := file_map.ProcessMapTrees(ctx, fileInputs)+ if err != nil {+ fmt.Printf("error processing map files: %v\n", err)+ os.Exit(1)+ }+ fmt.Println(trees.CombinedTrees())+ } else {+ mapBodies, err := file_map.ProcessMapFiles(ctx, fileInputs)+ if err != nil {+ fmt.Printf("error processing map files: %v\n", err)+ os.Exit(1)+ }- fmt.Println(mapBodies.CombinedMap())+ fmt.Println(mapBodies.CombinedMap())+ }}diff --git a/app/server/syntax/map_examples/bash_example.sh b/app/server/syntax/file_map/examples/bash_example.shsimilarity index 100%rename from app/server/syntax/map_examples/bash_example.shrename to app/server/syntax/file_map/examples/bash_example.shdiff --git a/app/server/syntax/map_examples/c_example.c b/app/server/syntax/file_map/examples/c_example.csimilarity index 100%rename from app/server/syntax/map_examples/c_example.crename to app/server/syntax/file_map/examples/c_example.cdiff --git a/app/server/syntax/map_examples/cpp_example.cpp b/app/server/syntax/file_map/examples/cpp_example.cppsimilarity index 83%rename from app/server/syntax/map_examples/cpp_example.cpprename to app/server/syntax/file_map/examples/cpp_example.cppindex 61b57302..a628b460 100644--- a/app/server/syntax/map_examples/cpp_example.cpp+++ b/app/server/syntax/file_map/examples/cpp_example.cpp@@ -4,16 +4,31 @@#include <string>#include <functional>+// Global variables at file scope+int globalInteger = 42;+const double PI = 3.14159;+static std::string globalString = "Global static string";++// Global enum and constant+enum Color { RED, GREEN, BLUE };+constexpr int MAX_SIZE = 100;+// Template classtemplate<typename T>class Container {public:+ static T defaultValue; // Static class member+ const T maxCapacity = MAX_SIZE; // Class constantvoid add(T item) { items.push_back(item); }const std::vector<T>& getItems() const { return items; }private:std::vector<T> items;};+// Static member definition+template<typename T>+T Container<T>::defaultValue = T();+// Abstract base classclass Animal {public:@@ -34,6 +49,10 @@ public:// Namespace examplenamespace Utils {+ // Namespace-level variables+ inline int counter = 0;+ const std::string VERSION = "1.0.0";+// Function templatetemplate<typename T>T max(T a, T b) {diff --git a/app/server/syntax/map_examples/csharp_example.cs b/app/server/syntax/file_map/examples/csharp_example.cssimilarity index 100%rename from app/server/syntax/map_examples/csharp_example.csrename to app/server/syntax/file_map/examples/csharp_example.csdiff --git a/app/server/syntax/map_examples/css_example.css b/app/server/syntax/file_map/examples/css_example.csssimilarity index 100%rename from app/server/syntax/map_examples/css_example.cssrename to app/server/syntax/file_map/examples/css_example.cssdiff --git a/app/server/syntax/map_examples/cue_example.cue b/app/server/syntax/file_map/examples/cue_example.cuesimilarity index 100%rename from app/server/syntax/map_examples/cue_example.cuerename to app/server/syntax/file_map/examples/cue_example.cuediff --git a/app/server/syntax/map_examples/dockerfile_example b/app/server/syntax/file_map/examples/dockerfile_examplesimilarity index 100%rename from app/server/syntax/map_examples/dockerfile_examplerename to app/server/syntax/file_map/examples/dockerfile_examplediff --git a/app/server/syntax/file_map/examples/elixir_example.ex b/app/server/syntax/file_map/examples/elixir_example.exnew file mode 100644index 00000000..a04ab214--- /dev/null+++ b/app/server/syntax/file_map/examples/elixir_example.ex@@ -0,0 +1,80 @@+defmodule ExampleApp do+ # Module attributes+ @default_timeout 5000+ @version "1.0.0"++ # Protocol definition+ defprotocol Formatter do+ @doc "Format the data for display"+ def format(data)+ end++ # Protocol implementation+ defimpl Formatter, for: Map do+ def format(data) do+ inspect(data, pretty: true)+ end+ end++ # Struct definition+ defstruct name: "", age: 0, email: nil++ # Exception definition+ defexception message: "A custom error occurred"++ # Callback definition+ @callback process(term) :: {:ok, term} | {:error, term}+ @macrocallback validate(term) :: Macro.t()++ # Public function+ def calculate_age(birth_year) when is_integer(birth_year) do+ current_year = DateTime.utc_now().year+ current_year - birth_year+ end++ # Private function+ defp validate_email(email) do+ String.match?(email, ~r/^[^\s]+@[^\s]+\.[^\s]+$/)+ end++ # Function with pattern matching+ def handle_result({:ok, value}), do: "Success: #{value}"+ def handle_result({:error, reason}), do: "Error: #{reason}"+ def handle_result(_), do: "Unknown result"++ # Macro definition+ defmacro debug(expression) do+ quote do+ IO.puts "Debug: #{inspect(unquote(expression))}"+ end+ end++ # Private macro+ defmacrop log(message) do+ quote do+ IO.puts("[#{__MODULE__}] #{unquote(message)}")+ end+ end++ # Guard definition+ defguard is_positive(value) when is_integer(value) and value > 0+ defguardp is_even(value) when is_integer(value) and rem(value, 2) == 0++ # Function delegation+ defdelegate parse_int(string), to: String, as: :to_integer++ # Overridable function+ defoverridable [process: 1]++ # Using with for complex operations+ def create_user(params) do+ with {:ok, name} <- Map.fetch(params, "name"),+ {:ok, email} <- Map.fetch(params, "email"),+ true <- validate_email(email) do+ %ExampleApp{name: name, email: email}+ else+ :error -> {:error, "Missing required fields"}+ false -> {:error, "Invalid email format"}+ end+ end+end\ No newline at end of filediff --git a/app/server/syntax/map_examples/elm_example.elm b/app/server/syntax/file_map/examples/elm_example.elmsimilarity index 100%rename from app/server/syntax/map_examples/elm_example.elmrename to app/server/syntax/file_map/examples/elm_example.elmdiff --git a/app/server/syntax/map_examples/go_example.go b/app/server/syntax/file_map/examples/go_example.gosimilarity index 95%rename from app/server/syntax/map_examples/go_example.gorename to app/server/syntax/file_map/examples/go_example.goindex b9ae30d0..e1391749 100644--- a/app/server/syntax/map_examples/go_example.go+++ b/app/server/syntax/file_map/examples/go_example.go@@ -2,7 +2,6 @@ package mainimport ("context"- "encoding/json""fmt""log""sync"@@ -43,12 +42,18 @@ const (DefaultLimit = 100)+// single line const+const singleLineConst string = "single line const"+// Global variablesvar (defaultTimeout = time.Second * 30processor DataProcessor)+// single line var+var singleLineVar string = "single line var"+// Generic typetype Result[T any] struct {Data Tdiff --git a/app/server/syntax/file_map/examples/groovy_example.groovy b/app/server/syntax/file_map/examples/groovy_example.groovynew file mode 100644index 00000000..9a73af78--- /dev/null+++ b/app/server/syntax/file_map/examples/groovy_example.groovy@@ -0,0 +1,164 @@+#!/usr/bin/env groovy++// Trait definition+trait Loggable {+ def log(String message) {+ println "[${new Date()}] $message"+ }+}++// Abstract class definition+abstract class Vehicle {+ String make+ String model+ Integer year++ abstract void start()+ abstract void stop()+}++// Class implementation - fixed inheritance syntax+class Car extends Vehicle implements Loggable {+ // Properties with type definitions+ private BigDecimal price+ protected Boolean running = false++ // Static fields with proper type declarations+ static final String MANUFACTURER = "Generic Motors"+ static int carCount = 0++ // Constructor - fixed parameter initialization+ Car(String make = 'Unknown', String model = 'Generic', Integer year = 2024) {+ this.make = make+ this.model = model+ this.year = year+ carCount+++ }++ // Lazy property evaluation+ @Lazy String fullName = "$make $model ($year)"++ // Method implementation with synchronized block+ void start() {+ running = true+ log("Starting ${fullName}")+ synchronized(this) {+ println("Engine started")+ }+ }++ void stop() {+ running = false+ log("Stopping ${fullName}")+ }++ // Operator overloading - fixed map construction+ def plus(Car other) {+ return new Car(+ make: "${this.make}-${other.make}",+ model: "${this.model}-${other.model}",+ year: Math.max(this.year, other.year)+ )+ }++ // Property accessors+ private BigDecimal _price++ void setPrice(BigDecimal price) {+ if (price < 0) {+ throw new IllegalArgumentException("Price cannot be negative")+ }+ this._price = price+ }++ BigDecimal getPrice() {+ return _price+ }+}++// Enum definition+enum Status {+ ACTIVE('A'),+ INACTIVE('I'),+ PENDING('P')++ final String code++ private Status(String code) {+ this.code = code+ }++ @Override+ String toString() {+ return code+ }+}++// Category class with explicit return+class StringExtensions {+ static String truncate(String self, Integer length) {+ return self.size() <= length ? self : self[0..<length] + "..."+ }+}++// Builder pattern class with proper return statements+class EmailBuilder {+ private Map email = [:]++ EmailBuilder to(String recipient) {+ email.to = recipient+ return this+ }++ EmailBuilder from(String sender) {+ email.from = sender+ return this+ }++ EmailBuilder subject(String subject) {+ email.subject = subject+ return this+ }++ EmailBuilder body(@DelegatesTo(StringBuilder) Closure body) {+ def builder = new StringBuilder()+ body.delegate = builder+ body.resolveStrategy = Closure.DELEGATE_FIRST+ body()+ email.body = builder.toString()+ return this+ }++ Map build() {+ return email.clone() as Map+ }+}++// Main execution with proper closure syntax+def main() {+ use(StringExtensions) {+ def description = "This is a very long description that needs truncating"+ println(description.truncate(20))+ }++ def car = new Car(make: "Tesla", model: "Model S")+ car.start()++ def email = new EmailBuilder()+ .to("[email protected]")+ .from("[email protected]")+ .subject("Test Email")+ .body {+ append("Hello\n")+ append("This is a test email.\n")+ append("Regards")+ }+ .build()++ println(email)+}++// Script execution with proper binding check+if (this.binding.hasVariable('main')) {+ main()+}\ No newline at end of filediff --git a/app/server/syntax/map_examples/hcl_example.hcl b/app/server/syntax/file_map/examples/hcl_example.hclsimilarity index 100%rename from app/server/syntax/map_examples/hcl_example.hclrename to app/server/syntax/file_map/examples/hcl_example.hcldiff --git a/app/server/syntax/map_examples/html_example.html b/app/server/syntax/file_map/examples/html_example.htmlsimilarity index 100%rename from app/server/syntax/map_examples/html_example.htmlrename to app/server/syntax/file_map/examples/html_example.htmldiff --git a/app/server/syntax/map_examples/java_example.java b/app/server/syntax/file_map/examples/java_example.javasimilarity index 100%rename from app/server/syntax/map_examples/java_example.javarename to app/server/syntax/file_map/examples/java_example.javadiff --git a/app/server/syntax/map_examples/javascript_example.js b/app/server/syntax/file_map/examples/javascript_example.jssimilarity index 100%rename from app/server/syntax/map_examples/javascript_example.jsrename to app/server/syntax/file_map/examples/javascript_example.jsdiff --git a/app/server/syntax/map_examples/kotlin_example.kt b/app/server/syntax/file_map/examples/kotlin_example.ktsimilarity index 100%rename from app/server/syntax/map_examples/kotlin_example.ktrename to app/server/syntax/file_map/examples/kotlin_example.ktdiff --git a/app/server/syntax/map_examples/lua_example.lua b/app/server/syntax/file_map/examples/lua_example.luasimilarity index 100%rename from app/server/syntax/map_examples/lua_example.luarename to app/server/syntax/file_map/examples/lua_example.luadiff --git a/app/server/syntax/map_examples/ocaml_example.ml b/app/server/syntax/file_map/examples/ocaml_example.mlsimilarity index 100%rename from app/server/syntax/map_examples/ocaml_example.mlrename to app/server/syntax/file_map/examples/ocaml_example.mldiff --git a/app/server/syntax/map_examples/php_example.php b/app/server/syntax/file_map/examples/php_example.phpsimilarity index 100%rename from app/server/syntax/map_examples/php_example.phprename to app/server/syntax/file_map/examples/php_example.phpdiff --git a/app/server/syntax/map_examples/protobuf_example.proto b/app/server/syntax/file_map/examples/protobuf_example.protosimilarity index 100%rename from app/server/syntax/map_examples/protobuf_example.protorename to app/server/syntax/file_map/examples/protobuf_example.protodiff --git a/app/server/syntax/map_examples/python_example.py b/app/server/syntax/file_map/examples/python_example.pysimilarity index 100%rename from app/server/syntax/map_examples/python_example.pyrename to app/server/syntax/file_map/examples/python_example.pydiff --git a/app/server/syntax/map_examples/ruby_example.rb b/app/server/syntax/file_map/examples/ruby_example.rbsimilarity index 99%rename from app/server/syntax/map_examples/ruby_example.rbrename to app/server/syntax/file_map/examples/ruby_example.rbindex 9c7802e1..6aee00ec 100644--- a/app/server/syntax/map_examples/ruby_example.rb+++ b/app/server/syntax/file_map/examples/ruby_example.rb@@ -1,5 +1,7 @@#!/usr/bin/env ruby+global_var = "Hello, World!"+# Module for mixing in common functionalitymodule Loggabledef log(message)diff --git a/app/server/syntax/map_examples/rust_example.rs b/app/server/syntax/file_map/examples/rust_example.rssimilarity index 100%rename from app/server/syntax/map_examples/rust_example.rsrename to app/server/syntax/file_map/examples/rust_example.rsdiff --git a/app/server/syntax/map_examples/scala_example.scala b/app/server/syntax/file_map/examples/scala_example.scalasimilarity index 100%rename from app/server/syntax/map_examples/scala_example.scalarename to app/server/syntax/file_map/examples/scala_example.scaladiff --git a/app/server/syntax/map_examples/svelte_example.svelte b/app/server/syntax/file_map/examples/svelte_example.sveltesimilarity index 100%rename from app/server/syntax/map_examples/svelte_example.svelterename to app/server/syntax/file_map/examples/svelte_example.sveltediff --git a/app/server/syntax/map_examples/swift_example.swift b/app/server/syntax/file_map/examples/swift_example.swiftsimilarity index 100%rename from app/server/syntax/map_examples/swift_example.swiftrename to app/server/syntax/file_map/examples/swift_example.swiftdiff --git a/app/server/syntax/map_examples/toml_example.toml b/app/server/syntax/file_map/examples/toml_example.tomlsimilarity index 100%rename from app/server/syntax/map_examples/toml_example.tomlrename to app/server/syntax/file_map/examples/toml_example.tomldiff --git a/app/server/syntax/map_examples/tsx_example.tsx b/app/server/syntax/file_map/examples/tsx_example.tsxsimilarity index 100%rename from app/server/syntax/map_examples/tsx_example.tsxrename to app/server/syntax/file_map/examples/tsx_example.tsxdiff --git a/app/server/syntax/map_examples/typescript_example.ts b/app/server/syntax/file_map/examples/typescript_example.tssimilarity index 100%rename from app/server/syntax/map_examples/typescript_example.tsrename to app/server/syntax/file_map/examples/typescript_example.tsdiff --git a/app/server/syntax/map_examples/yaml_example.yaml b/app/server/syntax/file_map/examples/yaml_example.yamlsimilarity index 97%rename from app/server/syntax/map_examples/yaml_example.yamlrename to app/server/syntax/file_map/examples/yaml_example.yamlindex a486d07c..cc36701b 100644--- a/app/server/syntax/map_examples/yaml_example.yaml+++ b/app/server/syntax/file_map/examples/yaml_example.yaml@@ -112,7 +112,7 @@ certificate: !!binary |R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOf...# Custom tags-!!python/object:datetime.datetime+datetime_obj: !!python/object:datetime.datetimeyear: 2024month: 2day: 20diff --git a/app/server/syntax/file_map/map.go b/app/server/syntax/file_map/map.gonew file mode 100644index 00000000..7f4e9ddf--- /dev/null+++ b/app/server/syntax/file_map/map.go@@ -0,0 +1,382 @@+package file_map++import (+ "context"+ "fmt"+ "os"+ "path/filepath"+ "plandex-server/syntax"+ "strings"++ "github.com/plandex/plandex/shared"+ tree_sitter "github.com/smacker/go-tree-sitter"+)++var verboseLogging = os.Getenv("VERBOSE_LOGGING") == "true"++// FileMap represents a file's important definitions+type FileMap struct {+ Definitions []Definition+}++type Definition struct {+ Type string // "function", "class", "key", "selector", "instruction" etc+ Signature string // The full signature/header without implementation+ Comments []string // Any comments that precede this definition+ TagAttrs []string // For xml style markup tags, the class and id attributes+ TagReps int // For tags, the number of times this tag is repeated+ Line int // Line number where definition starts+ Children []Definition // For parent types that can contain nested definitions+}++type Node struct {+ Type string+ Lang shared.TreeSitterLanguage+ TsNode *tree_sitter.Node+ Bytes []byte+}++func MapFile(ctx context.Context, filename string, content []byte) (*FileMap, error) {+ // Get appropriate parser+ var parser *tree_sitter.Parser+ var lang shared.TreeSitterLanguage+ file := filepath.Base(filename)+ if strings.Contains(strings.ToLower(file), "dockerfile") {+ lang = shared.TreeSitterLanguageDockerfile+ parser = syntax.GetParserForLanguage(lang)++ if parser == nil {+ return nil, fmt.Errorf("no parser found for dockerfile")+ }+ } else {+ ext := filepath.Ext(filename)+ parser, lang, _, _ = syntax.GetParserForExt(ext)++ if parser == nil {+ return nil, fmt.Errorf("unsupported file type: %s", ext)+ }+ }++ // Parse file+ tree, err := parser.ParseCtx(ctx, nil, content)+ if err != nil {+ return nil, fmt.Errorf("failed to parse file: %v", err)+ }+ defer tree.Close()++ // Create map+ m := &FileMap{+ Definitions: mapNode(tree.RootNode(), content, lang),+ }+ return m, nil+}++func mapNode(node *tree_sitter.Node, content []byte, lang shared.TreeSitterLanguage) []Definition {+ switch lang {+ case shared.TreeSitterLanguageHtml:+ return mapMarkup(content)+ case shared.TreeSitterLanguageSvelte:+ return mapSvelte(content)+ default:+ return mapTraditional(Node{+ Lang: lang,+ TsNode: node,+ Bytes: content,+ }, nil)+ }+}++// For traditional programming languages+func mapTraditional(baseNode Node, parentNode *Node) []Definition {+ var defs []Definition+ cursor := tree_sitter.NewTreeCursor(baseNode.TsNode)+ defer cursor.Close()++ if cursor.GoToFirstChild() {+ for {+ tsNode := cursor.CurrentNode()+ node := Node{+ Type: tsNode.Type(),+ Lang: baseNode.Lang,+ TsNode: tsNode,+ Bytes: baseNode.Bytes,+ }++ if isIncludeAndContinueNode(node) {+ if verboseLogging {+ fmt.Println("include and continue node", cursor.CurrentNode().Type())+ }+ if !cursor.GoToNextSibling() {+ break+ }+ continue+ }++ if verboseLogging {+ fmt.Println()+ fmt.Println("node", node.Type)+ // fmt.Println("content", string(node.Content(content)))+ fmt.Println()+ }++ // Check if this is a definition node+ if isDefinitionNode(node, parentNode) {+ if verboseLogging {+ fmt.Println("definition node", node.Type)+ }++ def := Definition{+ Type: node.Type,+ Line: int(tsNode.StartPoint().Row) + 1,+ }++ if isAssignmentNode(node) {+ if verboseLogging {+ fmt.Println("assignment node", node.Type)+ }+ // Try different field names for identifiers+ // fmt.Printf("assignment node: %s\n", node.Type)+ sig := ""++ assignmentBoundary := findAssignmentBoundary(node)++ if assignmentBoundary != nil {+ start := tsNode.StartByte()+ end := assignmentBoundary.TsNode.StartByte()+ sig = string(node.Bytes[start:end])+ sig = strings.TrimSuffix(strings.TrimSpace(sig), "=")+ } else {+ identifiers := findIdentifier(node)+ if len(identifiers) > 0 {+ if verboseLogging {+ fmt.Println("found identifiers", len(identifiers))+ }++ start := tsNode.StartByte()+ end := identifiers[len(identifiers)-1].TsNode.EndByte()+ sig = string(node.Bytes[start:end])+ } else {+ if verboseLogging {+ fmt.Println("no identifier found", node.Type)+ }+ sig = string(node.TsNode.Content(node.Bytes)) + " "+ }+ }++ def.Signature = sig+ } else if isPassThroughParentNode(node) {+ if verboseLogging {+ fmt.Println("pass through parent node", node.Type)+ }++ start := tsNode.StartByte()++ firstChild := firstDefinitionChild(node)+ if firstChild != nil {+ if verboseLogging {+ fmt.Println("firstChild", firstChild.Type)+ }+ end := firstChild.TsNode.StartByte()+ def.Signature = string(node.Bytes[start:end])++ if verboseLogging {+ fmt.Println("got pass through parent signature", def.Signature)+ fmt.Println("recursing into first child", firstChild.Type)+ }++ def.Children = mapTraditional(node, nil)+ } else {+ if verboseLogging {+ fmt.Println("no first child found", node.Type)+ }+ }++ } else {+ if verboseLogging {+ fmt.Println("not assignment node", node.Type)+ fmt.Println("looking for implementation boundary")+ }+ // Get signature (up to body)+ if body := findImplementationBoundary(node); body != nil {+ if verboseLogging {+ fmt.Println("found implementation boundary", body.Type)+ }++ start := tsNode.StartByte()+ var end uint32+ if tsNode == body.TsNode {+ if verboseLogging {+ fmt.Println("node == body")+ }+ firstChild := firstDefinitionChild(*body)+ if firstChild != nil {+ if verboseLogging {+ fmt.Println("firstChild != nil")+ fmt.Println("firstChild", firstChild.Type)+ }+ end = firstChild.TsNode.StartByte()+ } else {+ if verboseLogging {+ fmt.Println("firstChild == nil")+ }+ end = body.TsNode.EndByte()+ }+ } else {+ end = body.TsNode.StartByte()+ }+ if verboseLogging {+ fmt.Println("start", start)+ fmt.Println("end", end)+ }+ def.Signature = string(node.Bytes[start:end])+ if verboseLogging {+ fmt.Println("got signature", def.Signature)+ }++ // If this is a parent type node, recurse into the body+ if isParentNode(node) {+ if verboseLogging {+ fmt.Println("isParentNode, recursing into body", node.Type)+ }+ def.Children = mapTraditional(*body, &node)+ }+ } else {+ if verboseLogging {+ fmt.Println("no implementation boundary found", node.Type)+ }+ def.Signature = string(node.TsNode.Content(node.Bytes))+ }+ }++ // Get preceding comments+ // no comments for now to minimize tokens+ // def.Comments = getPrecedingComments(node)++ defs = append(defs, def)+ } else {+ if verboseLogging {+ fmt.Println("not definition node", node.Type)+ }+ }++ if !cursor.GoToNextSibling() {+ break+ }+ }+ }++ return defs+}++// // Get preceding comments+// func getPrecedingComments(node Node) []string {+// var comments []string+// const maxCommentLength = 1000++// prevNode := node.TsNode.PrevSibling()+// for prevNode != nil {+// if !strings.Contains(prevNode.Type(), "comment") {+// break+// }+// comment := string(prevNode.Content(node.Bytes))+// if len(comment) > maxCommentLength {+// comment = comment[:maxCommentLength] + "..."+// }+// comments = append([]string{comment}, comments...)+// prevNode = prevNode.PrevSibling()+// }+// return comments+// }++// func mapConfig(node *tree_sitter.Node, content []byte) []Definition {+// cursor := tree_sitter.NewTreeCursor(node)+// defer cursor.Close()++// var walkConfig func(*tree_sitter.Node) []Definition+// walkConfig = func(node *tree_sitter.Node) []Definition {+// var defs []Definition++// // Handle key-value pairs+// switch node.Type() {+// case "block_mapping_pair": // YAML+// if key := node.ChildByFieldName("key"); key != nil {+// def := Definition{+// Type: "key",+// Signature: string(key.Content(content)),+// Line: int(key.StartPoint().Row) + 1,+// }++// // Handle nested structures+// if val := node.ChildByFieldName("value"); val != nil {+// switch val.Type() {+// case "block_mapping": // nested YAML map+// def.Children = walkConfig(val)+// case "block_sequence": // YAML array+// // Could track sequences if needed+// }+// }++// defs = append(defs, def)+// }+// case "pair": // TOML/JSON+// // Similar pattern for TOML/JSON+// case "field": // CUE/HCL+// // Similar pattern for CUE/HCL+// }++// return defs+// }++// return walkConfig(node)+// }++func (m *FileMap) String() string {+ var b strings.Builder++ var writeDefinition func(def *Definition, depth int)+ writeDefinition = func(def *Definition, depth int) {+ if def.Type == "svelte-style" {+ b.WriteString("\n")+ }++ // Indent+ if depth > 0 {+ b.WriteString(strings.Repeat(" ", depth))+ b.WriteString("- ")+ }++ // Write signature (for tags, include attrs)+ if def.Type == "tag" {+ // Extract tag name from signature (it's the first word)+ tagName := strings.Fields(def.Signature)[0]+ // Build full representation with attrs+ if len(def.TagAttrs) > 0 {+ if def.TagReps > 1 {+ b.WriteString(fmt.Sprintf("[%dx]", def.TagReps))+ }+ b.WriteString(fmt.Sprintf("%s%s", tagName, strings.Join(def.TagAttrs, "")))+ } else {+ b.WriteString(tagName)+ }+ } else {+ b.WriteString(strings.TrimSpace(def.Signature))+ }+ b.WriteString("\n")++ // Write children with increased depth+ for _, child := range def.Children {+ writeDefinition(&child, depth+1)+ }++ if def.Type == "svelte-script" {+ b.WriteString("\n")+ }+ }++ // Write all top-level definitions+ for _, def := range m.Definitions {+ writeDefinition(&def, 0)+ }++ return b.String()+}diff --git a/app/server/syntax/file_map/markup.go b/app/server/syntax/file_map/markup.gonew file mode 100644index 00000000..1ee091db--- /dev/null+++ b/app/server/syntax/file_map/markup.go@@ -0,0 +1,157 @@+package file_map++import (+ "bytes"+ "fmt"+ "strings"++ "golang.org/x/net/html"+)++func mapMarkup(content []byte) []Definition {+ reader := bytes.NewReader(content)+ doc, err := html.Parse(reader)+ if err != nil {+ return nil+ }++ var walk func(*html.Node) []Definition+ walk = func(n *html.Node) []Definition {+ var defs []Definition++ if n.Type == html.ElementNode {+ // Only track semantically significant elements+ if isSignificantTag(n.Data) {+ def := Definition{+ Type: "tag",+ Signature: n.Data,+ }++ // Only include semantic classes/ids+ for _, attr := range n.Attr {+ if attr.Key == "id" {+ def.TagAttrs = append(def.TagAttrs, fmt.Sprintf("#%s", attr.Val))+ } else if attr.Key == "class" {+ classes := strings.Fields(attr.Val)+ if len(classes) > 3 {+ classes = classes[:3]+ }+ def.TagAttrs = append(def.TagAttrs, fmt.Sprintf(".%s", strings.Join(classes, ".")))+ }+ }++ // Get children of this element+ def.Children = []Definition{}+ for c := n.FirstChild; c != nil; c = c.NextSibling {+ def.Children = append(def.Children, walk(c)...)+ }++ defs = append(defs, def)+ }+ }++ // Only process siblings for non-significant elements+ if !isSignificantTag(n.Data) {+ for c := n.FirstChild; c != nil; c = c.NextSibling {+ defs = append(defs, walk(c)...)+ }+ }++ return defs+ }++ defs := walk(doc)+ defs = consolidateRepeatedTags(defs)+ return defs+}++// Helper function to check if two definitions are equivalent+func areMarkupDefinitionsEqual(a, b Definition) bool {+ if a.Type != b.Type || a.Signature != b.Signature || len(a.TagAttrs) != len(b.TagAttrs) {+ return false+ }++ // Compare attributes+ for i, attr := range a.TagAttrs {+ if attr != b.TagAttrs[i] {+ return false+ }+ }++ return true+}++// Helper function to consolidate repeated tags+func consolidateRepeatedTags(defs []Definition) []Definition {+ var result []Definition++ firstDef := defs[0]+ count := 1+ allEqual := true++ // fmt.Printf("consolidateRepeatedTags: checking %d definitions for equality\n", len(defs))+ // spew.Dump(defs)++ if len(defs) > 1 {+ for i, def := range defs {+ if len(def.Children) > 0 {+ // fmt.Printf("consolidateRepeatedTags: definition %d has children, cannot consolidate\n", i)+ allEqual = false+ break+ }++ if i == 0 {+ continue+ }++ if !areMarkupDefinitionsEqual(firstDef, def) {+ // fmt.Printf("consolidateRepeatedTags: definition %d is not equal to first definition\n", i)+ allEqual = false+ break+ }+ count+++ }+ }++ if allEqual && count > 1 {+ // fmt.Printf("consolidateRepeatedTags: consolidated %d equal definitions\n", count)+ firstDef.TagReps = count+ result = []Definition{firstDef}+ } else {+ // fmt.Printf("consolidateRepeatedTags: definitions not equal, keeping original %d definitions\n", len(defs))+ result = defs+ }++ for i := range result {+ def := &result[i]+ if len(def.Children) > 0 {+ // fmt.Printf("consolidateRepeatedTags: recursively consolidating children of definition %d\n", i)+ def.Children = consolidateRepeatedTags(def.Children)+ }+ }++ return result+}++var significantHtmlTags = map[string]bool{+ "html": true,+ "head": true,+ "body": true,+ "main": true,+ "nav": true,+ "header": true,+ "footer": true,+ "article": true,+ "section": true,+ "form": true,+ "dialog": true,+ "template": true,+ "table": true,+ "div": true,+ "ul": true,+ "aside": true,+}++func isSignificantTag(tag string) bool {+ return significantHtmlTags[tag]+}diff --git a/app/server/syntax/file_map/multi.go b/app/server/syntax/file_map/multi.gonew file mode 100644index 00000000..a28a766e--- /dev/null+++ b/app/server/syntax/file_map/multi.go@@ -0,0 +1,116 @@+package file_map++import (+ "context"+ "fmt"+ "path/filepath"+ "plandex-server/syntax"+ "sort"+ "strings"+ "sync"++ "github.com/plandex/plandex/shared"+ tree_sitter "github.com/smacker/go-tree-sitter"+)++// handles concurrent processing of multiple files for mapping+func ProcessMapFiles(ctx context.Context, inputs map[string]string) (shared.FileMapBodies, error) {+ bodies := make(shared.FileMapBodies, len(inputs))+ var mu sync.Mutex+ errCh := make(chan error, len(inputs))++ for path, content := range inputs {+ go func(path, content string) {+ fileMap, err := MapFile(ctx, path, []byte(content))+ if err != nil {+ errCh <- fmt.Errorf("error mapping file %s: %v", path, err)+ return+ }+ mu.Lock()+ defer mu.Unlock()+ bodies[path] = fileMap.String()+ errCh <- nil+ }(path, content)+ }++ for i := 0; i < len(inputs); i++ {+ err := <-errCh+ if err != nil {+ return nil, err+ }+ }++ return bodies, nil+}++type MapTrees map[string]string++func ProcessMapTrees(ctx context.Context, inputs map[string]string) (MapTrees, error) {+ trees := make(MapTrees, len(inputs))+ var mu sync.Mutex+ errCh := make(chan error, len(inputs))++ for path, content := range inputs {+ go func(path, content string) {+ // Get appropriate parser+ var parser *tree_sitter.Parser+ file := filepath.Base(path)+ if strings.Contains(strings.ToLower(file), "dockerfile") {+ parser = syntax.GetParserForLanguage(shared.TreeSitterLanguageDockerfile)+ } else {+ ext := filepath.Ext(path)+ parser, _, _, _ = syntax.GetParserForExt(ext)++ if parser == nil {+ errCh <- fmt.Errorf("unsupported file type: %s", ext)+ return+ }+ }++ contentBytes := []byte(content)++ // Parse file+ tree, err := parser.ParseCtx(ctx, nil, contentBytes)+ if err != nil {+ errCh <- fmt.Errorf("failed to parse file: %v", err)+ return+ }+ defer tree.Close()++ mu.Lock()+ defer mu.Unlock()+ trees[path] = string(tree.RootNode().String())+ errCh <- nil+ }(path, content)+ }++ for i := 0; i < len(inputs); i++ {+ err := <-errCh+ if err != nil {+ return nil, err+ }+ }++ return trees, nil+}++func (m MapTrees) CombinedTrees() string {+ var combinedMap strings.Builder+ paths := make([]string, 0, len(m))+ for path := range m {+ paths = append(paths, path)+ }+ sort.Strings(paths)+ for _, path := range paths {+ body := m[path]+ body = strings.TrimSpace(body)+ if body == "" {+ continue+ }+ fileHeading := fmt.Sprintf("\n### %s\n", path)+ combinedMap.WriteString(fileHeading)+ combinedMap.WriteString(body)+ combinedMap.WriteString("\n")+ }+ return combinedMap.String()+}diff --git a/app/server/syntax/file_map/nodes_config.go b/app/server/syntax/file_map/nodes_config.gonew file mode 100644index 00000000..1d13f333--- /dev/null+++ b/app/server/syntax/file_map/nodes_config.go@@ -0,0 +1,819 @@+package file_map++import "github.com/plandex/plandex/shared"++type nodeType string++type matchType string++const (+ matchTypeEqual matchType = "equal"+ matchTypePrefix matchType = "prefix"+ matchTypeSuffix matchType = "suffix"+)++type langSet map[shared.TreeSitterLanguage]bool++type nodeConfig struct {+ nodeMatch matchType+ ignore bool+ all bool+ except langSet+ languages langSet+ onlyChildren map[nodeType]bool+}++type nodeMap map[nodeType]nodeConfig++var assignmentNodeMap = nodeMap{+ // Common patterns across many languages+ "assignment_expression": {+ nodeMatch: matchTypeEqual,+ all: true,+ },+ "declaration": {+ nodeMatch: matchTypeEqual,+ all: true,+ },+ "variable_declaration": {+ nodeMatch: matchTypeEqual,+ all: true,+ },+ "variable_assignment": {+ nodeMatch: matchTypeEqual,+ all: true,+ },++ "const_spec": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageGo: true,+ },+ },+ "var_spec": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageGo: true,+ },+ },++ "lexical_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageJavascript: true,+ shared.TreeSitterLanguageTypescript: true,+ shared.TreeSitterLanguageJsx: true,+ shared.TreeSitterLanguageTsx: true,+ },+ },++ "field_definition": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageJavascript: true,+ shared.TreeSitterLanguageTypescript: true,+ shared.TreeSitterLanguageJsx: true,+ shared.TreeSitterLanguageTsx: true,+ },+ },++ "interface_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageTypescript: true,+ shared.TreeSitterLanguageTsx: true,+ shared.TreeSitterLanguagePhp: true,+ },+ },++ "trait_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguagePhp: true,+ },+ },++ "enum_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguagePhp: true,+ shared.TreeSitterLanguageCsharp: true,+ },+ },++ "global_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguagePhp: true,+ },+ },+ "static_variable_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguagePhp: true,+ },+ },++ "type_alias_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageTypescript: true,+ shared.TreeSitterLanguageTsx: true,+ shared.TreeSitterLanguageElm: true,+ },+ },++ "assignment_statement": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguagePython: true,+ },+ },++ "class_variable_assignment": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRuby: true,+ },+ },+ "assignment": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRuby: true,+ },+ },++ "let_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRust: true,+ },+ },+ "const_item": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRust: true,+ },+ },++ "static_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageJava: true,+ shared.TreeSitterLanguageCsharp: true,+ },+ },+ "member_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageJava: true,+ shared.TreeSitterLanguageCsharp: true,+ },+ },+ "field_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageJava: true,+ shared.TreeSitterLanguageCsharp: true,+ },+ },++ "property_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageKotlin: true,+ shared.TreeSitterLanguageScala: true,+ shared.TreeSitterLanguagePhp: true,+ shared.TreeSitterLanguageSwift: true,+ },+ },++ "let_binding": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageOCaml: true,+ },+ },+ "value_binding": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageOCaml: true,+ },+ },++ "unary_operator": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageElixir: true,+ },+ },++ "value_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageElm: true,+ },+ },++ "declaration_command": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageBash: true,+ },+ },++ "type_item": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRust: true,+ },+ },++ "val_definition": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageScala: true,+ },+ },++ "type_definition": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageScala: true,+ },+ },++ "typealias_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageSwift: true,+ },+ },+}++var definitionNodeMap = nodeMap{+ // Common patterns across languages+ "_definition": {+ nodeMatch: matchTypeSuffix,+ all: true,+ },+ "_declaration": {+ nodeMatch: matchTypeSuffix,+ all: true,+ },+ "_declarator": {+ nodeMatch: matchTypeSuffix,+ all: true,+ },+ "_spec": {+ nodeMatch: matchTypeSuffix,+ all: true,+ },+ "_binding": {+ nodeMatch: matchTypeSuffix,+ all: true,+ },+ "_signature": {+ nodeMatch: matchTypeSuffix,+ all: true,+ },+ "declaration": {+ nodeMatch: matchTypeEqual,+ all: true,+ },+ "_specifier": {+ nodeMatch: matchTypeSuffix,+ all: true,+ },+ "interface_": {+ nodeMatch: matchTypePrefix,+ all: true,+ },++ // Language-specific definitions+ "def": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRuby: true,+ },+ },+ "method": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRuby: true,+ },+ },+ "defmodule": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageElixir: true,+ },+ },+ "defmacro": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageElixir: true,+ },+ },+ "port": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageElm: true,+ },+ },+ "functor": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageOCaml: true,+ },+ },+ "_def": {+ nodeMatch: matchTypeSuffix,+ languages: langSet{+ shared.TreeSitterLanguageC: true,+ shared.TreeSitterLanguageCpp: true,+ },+ },+ "type_annotation": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageElm: true,+ },+ },+ "function_statement": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageLua: true,+ },+ },+ "rule_set": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageCss: true,+ },+ },+ "from_instruction": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageDockerfile: true,+ },+ },+ "entrypoint_instruction": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageDockerfile: true,+ },+ },+ "cmd_instruction": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageDockerfile: true,+ },+ },+ "expose_instruction": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageDockerfile: true,+ },+ },+ "copy_instruction": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageDockerfile: true,+ },+ },+ "env_instruction": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageDockerfile: true,+ },+ },++ // Ignored patterns+ "import_": {+ nodeMatch: matchTypePrefix,+ ignore: true,+ all: true,+ },+ "require_": {+ nodeMatch: matchTypePrefix,+ ignore: true,+ all: true,+ },+ "use_": {+ nodeMatch: matchTypePrefix,+ ignore: true,+ all: true,+ },+ "namespace_use_": {+ nodeMatch: matchTypePrefix,+ ignore: true,+ all: true,+ },+ "using_": {+ nodeMatch: matchTypePrefix,+ ignore: true,+ all: true,+ },+ "include_": {+ nodeMatch: matchTypePrefix,+ ignore: true,+ all: true,+ },+ "package_": {+ nodeMatch: matchTypePrefix,+ ignore: true,+ all: true,+ },+ "_include": {+ nodeMatch: matchTypeSuffix,+ ignore: true,+ languages: langSet{+ shared.TreeSitterLanguageC: true,+ shared.TreeSitterLanguageCpp: true,+ },+ },+ "_item": {+ nodeMatch: matchTypeSuffix,+ languages: langSet{+ shared.TreeSitterLanguageRust: true,+ },+ },+}++var parentNodeMap = nodeMap{+ // Common patterns+ "class_": {+ nodeMatch: matchTypePrefix,+ all: true,+ },+ "module_": {+ nodeMatch: matchTypePrefix,+ all: true,+ },+ "namespace_": {+ nodeMatch: matchTypePrefix,+ all: true,+ },++ // Language-specific parents+ "object": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageScala: true,+ },+ },+ "object_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageKotlin: true,+ },+ },+ "protocol": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageSwift: true,+ },+ },+ "protocol_": {+ nodeMatch: matchTypePrefix,+ languages: langSet{+ shared.TreeSitterLanguageElixir: true,+ },+ },+ "extension": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageSwift: true,+ },+ },++ "const_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageGo: true,+ },+ },++ "var_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageGo: true,+ },+ },++ "template_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageCpp: true,+ },+ },++ "module": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRuby: true,+ },+ },++ "class": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRuby: true,+ },+ },++ "singleton_class": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRuby: true,+ },+ },++ "enum_entry": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageKotlin: true,+ },+ },++ "closure": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageGroovy: true,+ },+ },++ "impl_item": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRust: true,+ },+ },++ "trait_item": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRust: true,+ },+ },++ "trait_definition": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageScala: true,+ },+ },++ "object_definition": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageScala: true,+ },+ },++ "function_statement": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageLua: true,+ },+ onlyChildren: map[nodeType]bool{+ "function_statement": true,+ },+ },+}++var implBoundaryNodeMap = nodeMap{+ // Common patterns+ "block": {+ nodeMatch: matchTypeEqual,+ all: true,+ except: langSet{+ shared.TreeSitterLanguageRuby: true,+ shared.TreeSitterLanguageElixir: true,+ },+ },+ "body": {+ nodeMatch: matchTypeEqual,+ all: true,+ },+ "_body": {+ nodeMatch: matchTypeSuffix,+ all: true,+ },+ "compound_statement": {+ nodeMatch: matchTypeEqual,+ all: true,+ },++ // Language-specific boundaries+ "do_block": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRuby: true,+ shared.TreeSitterLanguageElixir: true,+ },+ },+ "body_statement": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRuby: true,+ },+ },+ "field_declaration_list": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageGo: true,+ shared.TreeSitterLanguageC: true,+ shared.TreeSitterLanguageCpp: true,+ },+ },+ "property_accessors": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageCsharp: true,+ shared.TreeSitterLanguageSwift: true,+ },+ },+ "const_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageGo: true,+ },+ },+ "var_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageGo: true,+ },+ },+ "method_elem": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageGo: true,+ },+ },++ "preproc_arg": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageC: true,+ shared.TreeSitterLanguageCpp: true,+ },+ },++ "statement_block": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageJavascript: true,+ shared.TreeSitterLanguageTypescript: true,+ shared.TreeSitterLanguageJsx: true,+ shared.TreeSitterLanguageTsx: true,+ },+ },++ "declaration_list": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguagePhp: true,+ shared.TreeSitterLanguageCsharp: true,+ shared.TreeSitterLanguageRust: true,+ },+ },++ "_declaration_list": {+ nodeMatch: matchTypeSuffix,+ languages: langSet{+ shared.TreeSitterLanguageRust: true,+ },+ },++ "enum_variant_list": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRust: true,+ },+ },++ "=": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageScala: true,+ },+ },+}++var assignmentBoundaryNodeMap = nodeMap{+ "=": {+ nodeMatch: matchTypeEqual,+ all: true,+ },+ ":=": {+ nodeMatch: matchTypeEqual,+ all: true,+ },+ "<-": {+ nodeMatch: matchTypeEqual,+ all: true,+ },+ "expression": {+ nodeMatch: matchTypeEqual,+ all: true,+ },+ "interface_body": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageTypescript: true,+ shared.TreeSitterLanguageTsx: true,+ },+ },+ "declaration_list": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguagePhp: true,+ shared.TreeSitterLanguageCsharp: true,+ },+ },+ "_declaration_list": {+ nodeMatch: matchTypeSuffix,+ languages: langSet{+ shared.TreeSitterLanguagePhp: true,+ shared.TreeSitterLanguageCsharp: true,+ },+ },+ "lambda_literal": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageKotlin: true,+ },+ },+ "arguments": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageElixir: true,+ },+ },+ "eq": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageElm: true,+ },+ },+ "statements": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageSwift: true,+ },+ },+}++var identifierNodeMap = nodeMap{+ // Common patterns+ "identifier": {+ nodeMatch: matchTypeEqual,+ all: true,+ },+ "_identifier": {+ nodeMatch: matchTypeSuffix,+ all: true,+ },++ // Language-specific identifiers+ "constant": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageRuby: true,+ },+ },+ "name": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguagePhp: true,+ },+ },+ "bare_key": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageToml: true,+ shared.TreeSitterLanguageYaml: true,+ },+ },+}++var passThroughParentNodeMap = nodeMap{+ "template_declaration": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageCpp: true,+ },+ },+}++var includeAndContinueNodeMap = nodeMap{+ "template_parameter_list": {+ nodeMatch: matchTypeEqual,+ languages: langSet{+ shared.TreeSitterLanguageCpp: true,+ },+ },+}diff --git a/app/server/syntax/file_map/nodes_find.go b/app/server/syntax/file_map/nodes_find.gonew file mode 100644index 00000000..44d52ee2--- /dev/null+++ b/app/server/syntax/file_map/nodes_find.go@@ -0,0 +1,297 @@+package file_map++import (+ "fmt"+ "strings"++ "github.com/plandex/plandex/shared"+)++func isDefinitionNode(node Node, parentNode *Node) bool {+ setNodeType(&node)++ res := false++ config := definitionNodeMap.getConfig(node.Type, node.Lang)++ var parentConfig *nodeConfig+ if parentNode != nil {+ parentConfig = parentNodeMap.getConfig(parentNode.Type, parentNode.Lang)+ }++ if config == nil {+ res = isAssignmentNode(node) || isParentNode(node)+ if res && parentConfig != nil && parentConfig.onlyChildren != nil {+ res = parentConfig.onlyChildren[nodeType(node.Type)]+ }+ return res+ }++ res = !config.ignore+ if res {+ if parentConfig != nil && parentConfig.onlyChildren != nil {+ res = parentConfig.onlyChildren[nodeType(node.Type)]+ }+ }+ return res+}++func isAssignmentNode(node Node) bool {+ setNodeType(&node)+ config := assignmentNodeMap.getConfig(node.Type, node.Lang)+ if config == nil {+ return false+ }+ return !config.ignore+}++func isParentNode(node Node) bool {+ setNodeType(&node)+ config := parentNodeMap.getConfig(node.Type, node.Lang)+ if config == nil {+ return false+ }+ return !config.ignore+}++func isImplBoundaryNode(node Node) bool {+ setNodeType(&node)+ config := implBoundaryNodeMap.getConfig(node.Type, node.Lang)+ if config == nil {+ return false+ }+ return !config.ignore+}++func isAssignmentBoundaryNode(node Node) bool {+ setNodeType(&node)+ config := assignmentBoundaryNodeMap.getConfig(node.Type, node.Lang)+ if config == nil {+ return false+ }+ return !config.ignore+}++func isIdentifierNode(node Node) bool {+ setNodeType(&node)+ config := identifierNodeMap.getConfig(node.Type, node.Lang)+ if config == nil {+ return false+ }+ return !config.ignore+}++func isPassThroughParentNode(node Node) bool {+ setNodeType(&node)+ config := passThroughParentNodeMap.getConfig(node.Type, node.Lang)+ if config == nil {+ return false+ }+ return !config.ignore+}++func isIncludeAndContinueNode(node Node) bool {+ setNodeType(&node)+ config := includeAndContinueNodeMap.getConfig(node.Type, node.Lang)+ if config == nil {+ return false+ }+ return !config.ignore+}++func (m nodeMap) getConfig(t string, lang shared.TreeSitterLanguage) *nodeConfig {+ // first look for exact match+ config, ok := m[nodeType(t)]+ if ok {+ if config.all {+ if config.except == nil || !config.except[lang] {+ return &config+ }+ }++ if config.languages != nil && config.languages[lang] {+ return &config+ }+ }++ // then look for prefix or suffix match+ var foundConfig *nodeConfig+ for k, config := range m {+ var maybeConfig *nodeConfig+ if config.nodeMatch == matchTypePrefix && strings.HasPrefix(t, string(k)) {+ maybeConfig = &config+ } else if config.nodeMatch == matchTypeSuffix && strings.HasSuffix(t, string(k)) {+ maybeConfig = &config+ }++ var wouldSet *nodeConfig+ if maybeConfig != nil {+ if maybeConfig.all {+ if maybeConfig.except == nil || !maybeConfig.except[lang] {+ wouldSet = maybeConfig+ }+ } else if maybeConfig.languages != nil && maybeConfig.languages[lang] {+ wouldSet = maybeConfig+ }+ }++ if wouldSet != nil {+ if foundConfig != nil {+ // ignore takes precedence+ if wouldSet.ignore {+ foundConfig = wouldSet+ }+ } else {+ foundConfig = wouldSet+ }+ }+ }++ return foundConfig+}++func findImplementationBoundary(node Node) *Node {+ if isImplBoundaryNode(node) {+ return &node+ }++ for i := 0; i < int(node.TsNode.ChildCount()); i++ {+ child := node.TsNode.Child(i)++ if verboseLogging {+ fmt.Println(" findImplementationBoundary child", child.Type())+ }++ childNode := Node{+ Type: child.Type(),+ Lang: node.Lang,+ TsNode: child,+ Bytes: node.Bytes,+ }++ if isImplBoundaryNode(childNode) {+ return &childNode+ } else {+ found := findImplementationBoundary(childNode)+ if found != nil {+ return found+ }+ }+ }+ return nil+}++func findIdentifier(node Node) []Node {+ if isIdentifierNode(node) {+ return []Node{node}+ }++ nodes := []Node{}+ for i := 0; i < int(node.TsNode.ChildCount()); i++ {+ child := node.TsNode.Child(i)+ childNode := Node{+ Type: child.Type(),+ Lang: node.Lang,+ TsNode: child,+ Bytes: node.Bytes,+ }++ if verboseLogging {+ fmt.Println(" child", child.Type())+ }++ found := findIdentifier(childNode)+ if found != nil {+ nodes = append(nodes, found...)+ }+ }+ return nodes+}++func firstDefinitionChild(node Node) *Node {+ for i := 0; i < int(node.TsNode.ChildCount()); i++ {+ child := node.TsNode.Child(i)++ if verboseLogging {+ fmt.Println(" child", child.Type())+ }++ childNode := Node{+ Type: child.Type(),+ Lang: node.Lang,+ TsNode: child,+ Bytes: node.Bytes,+ }++ if isDefinitionNode(childNode, &node) && !isIncludeAndContinueNode(childNode) {+ return &childNode+ }+ }+ return nil+}++func findAssignmentBoundary(node Node) *Node {+ if isAssignmentBoundaryNode(node) {+ return &node+ }++ for i := 0; i < int(node.TsNode.ChildCount()); i++ {+ child := node.TsNode.Child(i)++ childNode := Node{+ Type: child.Type(),+ Lang: node.Lang,+ TsNode: child,+ Bytes: node.Bytes,+ }++ if verboseLogging {+ fmt.Println(" child", child.Type())+ }++ found := findAssignmentBoundary(childNode)+ if found != nil {+ return found+ }+ }+ return nil+}++func setNodeType(node *Node) {+ if node.Lang == shared.TreeSitterLanguageElixir && node.Type == "call" {+ content := node.TsNode.Content(node.Bytes)++ switch {+ case strings.HasPrefix(string(content), "defmodule"):+ node.Type = "module_definition"+ case strings.HasPrefix(string(content), "defprotocol"):+ node.Type = "protocol_definition"+ case strings.HasPrefix(string(content), "defimpl"):+ node.Type = "protocol_implementation"+ case strings.HasPrefix(string(content), "defstruct"):+ node.Type = "struct_definition"+ case strings.HasPrefix(string(content), "defexception"):+ node.Type = "exception_definition"+ case strings.HasPrefix(string(content), "defdelegate"):+ node.Type = "delegate_definition"+ case strings.HasPrefix(string(content), "defoverridable"):+ node.Type = "overridable_definition"+ case strings.HasPrefix(string(content), "defcallback"):+ node.Type = "callback_definition"+ case strings.HasPrefix(string(content), "defmacrocallback"):+ node.Type = "macro_callback_definition"+ case strings.HasPrefix(string(content), "defmacrop"):+ node.Type = "private_macro_definition"+ case strings.HasPrefix(string(content), "defmacro"):+ node.Type = "macro_definition"+ case strings.HasPrefix(string(content), "defguardp"):+ node.Type = "private_guard_definition"+ case strings.HasPrefix(string(content), "defguard"):+ node.Type = "guard_definition"+ case strings.HasPrefix(string(content), "defp"):+ node.Type = "private_function_definition"+ case strings.HasPrefix(string(content), "def"):+ node.Type = "function_definition"+ }+ }+}diff --git a/app/server/syntax/file_map/svelte.go b/app/server/syntax/file_map/svelte.gonew file mode 100644index 00000000..171b8885--- /dev/null+++ b/app/server/syntax/file_map/svelte.go@@ -0,0 +1,119 @@+package file_map++import (+ "bytes"+ "context"+ "fmt"+ "log"+ "plandex-server/syntax"+ "strings"++ "github.com/plandex/plandex/shared"+ "golang.org/x/net/html"+)++func mapSvelte(content []byte) []Definition {+ scriptContent, scriptLang, styleContent := getSvelteScriptAndStyle(content)+ defs := []Definition{}++ if scriptContent != "" {+ var lang shared.TreeSitterLanguage+ if scriptLang == "ts" {+ lang = shared.TreeSitterLanguageTypescript+ } else {+ lang = shared.TreeSitterLanguageJavascript+ }++ parser := syntax.GetParserForLanguage(lang)+ tree, err := parser.ParseCtx(context.Background(), nil, []byte(scriptContent))+ if err != nil {+ log.Printf("mapSvelte - error parsing script content: %v\n", err)+ return defs+ }++ def := Definition{+ Type: "svelte-script",+ Signature: fmt.Sprintf("<script lang=%q>", scriptLang),+ Children: mapTraditional(Node{+ Lang: lang,+ TsNode: tree.RootNode(),+ Bytes: []byte(scriptContent),+ }, nil),+ }++ defs = append(defs, def)+ }++ defs = append(defs, mapMarkup(content)...)++ if styleContent != "" {+ parser := syntax.GetParserForLanguage(shared.TreeSitterLanguageCss)+ tree, err := parser.ParseCtx(context.Background(), nil, []byte(styleContent))+ if err != nil {+ log.Printf("mapSvelte - error parsing style content: %v\n", err)+ return defs+ }++ def := Definition{+ Type: "svelte-style",+ Signature: "<style>",+ Children: mapTraditional(Node{+ Lang: shared.TreeSitterLanguageCss,+ TsNode: tree.RootNode(),+ Bytes: []byte(styleContent),+ }, nil),+ }++ defs = append(defs, def)+ }++ return defs+}++func getSvelteScriptAndStyle(content []byte) (scriptContent, scriptLang, styleContent string) {+ reader := bytes.NewReader(content)+ doc, err := html.Parse(reader)+ if err != nil {+ return "", "", ""+ }++ // Helper function to extract text content from a node+ var getTextContent func(*html.Node) string+ getTextContent = func(n *html.Node) string {+ if n.Type == html.TextNode {+ return n.Data+ }+ var result string+ for c := n.FirstChild; c != nil; c = c.NextSibling {+ result += getTextContent(c)+ }+ return result+ }++ // Helper function to find script and style tags+ var findTags func(*html.Node)+ findTags = func(n *html.Node) {+ if n.Type == html.ElementNode {+ if n.Data == "script" {+ scriptContent = strings.TrimSpace(getTextContent(n))+ // Check for lang attribute+ for _, attr := range n.Attr {+ if attr.Key == "lang" {+ scriptLang = attr.Val+ break+ }+ }+ } else if n.Data == "style" {+ styleContent = strings.TrimSpace(getTextContent(n))+ }+ }++ // Recursively search children+ for c := n.FirstChild; c != nil; c = c.NextSibling {+ findTags(c)+ }+ }++ findTags(doc)+ return scriptContent, scriptLang, styleContent+}diff --git a/app/server/syntax/file_map_multi.go b/app/server/syntax/file_map_multi.godeleted file mode 100644index 581c304c..00000000--- a/app/server/syntax/file_map_multi.go+++ /dev/null@@ -1,39 +0,0 @@-package syntax--import (- "context"- "fmt"- "sync"-- "github.com/plandex/plandex/shared"-)--// handles concurrent processing of multiple files for mapping-func ProcessMapFiles(ctx context.Context, inputs map[string]string) (shared.FileMapBodies, error) {- bodies := make(shared.FileMapBodies, len(inputs))- var mu sync.Mutex- errCh := make(chan error, len(inputs))-- for path, content := range inputs {- go func(path, content string) {- fileMap, err := MapFile(ctx, path, []byte(content))- if err != nil {- errCh <- fmt.Errorf("error mapping file %s: %v", path, err)- return- }- mu.Lock()- defer mu.Unlock()- bodies[path] = fileMap.String()- errCh <- nil- }(path, content)- }-- for i := 0; i < len(inputs); i++ {- err := <-errCh- if err != nil {- return nil, err- }- }-- return bodies, nil-}diff --git a/app/server/syntax/map.txt b/app/server/syntax/map.txtnew file mode 100644index 00000000..7943fa91--- /dev/null+++ b/app/server/syntax/map.txt@@ -0,0 +1,846 @@+### ../examples/bash_example.sh+function print_message()+get_date()+main()++### ../examples/c_example.c+#define MAX_SIZE+#define SQUARE(x)+typedef struct+typedef enum {+ MONDAY,+ TUESDAY,+ WEDNESDAY,+ THURSDAY,+ FRIDAY+} Weekday;+static const double PI+int globalCounter+void printPerson(const Person* p+int factorial(int n+union Data+typedef int (*Operation)(int, int);+int add(int a, int b)+int subtract(int a, int b)+void printPerson(const Person* p)+int factorial(int n)+int main()++### ../examples/cpp_example.cpp+int globalInteger+const double PI+static std::string globalString+enum Color { RED, GREEN, BLUE }+constexpr int MAX_SIZE+template<typename T>+ - class Container+ - public+ - static T defaultValue;+ - const T maxCapacity = MAX_SIZE;+ - void add(T item)+ - const std::vector<T>& getItems() const+ - private+ - std::vector<T> items;+template<typename T>+ - T Container<T>::defaultValue+class Animal+ - public+ - virtual ~Animal() = default;+ - virtual void makeSound() const = 0;+ - protected+ - std::string name;+class Dog : virtual public Animal+ - public+ - Dog(const std::string& dogName)+ - void makeSound() const override+namespace Utils {+ // Namespace-level variables+ inline int counter = 0;+ const std::string VERSION = "1.0.0";++ // Function template+ template<typename T>+ T max(T a, T b)+class Resource+ - public+ - Resource(const std::string& data) : data_(data)+ - ~Resource()+ - Resource(Resource&& other) noexcept : data_(std::move(other.data_))+ - std::string getData() const+ - private+ - std::string data_;+class Counter+ - public+ - static int getCount()+ - Counter()+ - ~Counter()+ - private+ - static int count;+int Counter::count+class Box+ - friend std::ostream& operator<<(std::ostream& os, const Box& box);+ - public+ - Box(int w, int h) : width(w), height(h)+ - private+ - int width;+ - int height;+std::ostream& operator<<(std::ostream& os, const Box& box)+int main()++### ../examples/csharp_example.cs+namespace ExampleApp+{+ // Interface definition+ public interface IProcessor<T>+ {+ Task<T> ProcessAsync(T input);+ bool Validate(T input);+ }++ // Enum definition+ public enum Status+ {+ Pending,+ Active,+ Completed,+ Failed+ }++ // Delegate declaration+ public delegate void StatusChangedEventHandler(Status oldStatus, Status newStatus);++ // Generic class implementing interface+ public class DataProcessor<T> : IProcessor<T> where T : class+ {+ // Event declaration+ public event StatusChangedEventHandler StatusChanged;++ // Auto-implemented property+ public Status CurrentStatus { get; private set; }++ // Static field+ private static readonly Dictionary<Type, int> _processedItems = new();++ // Constructor+ public DataProcessor()++### ../examples/elm_example.elm+type alias Model =+ { users : List User+ , inputText : String+ , error : Maybe String+ }+type alias User =+ { id : Int+ , name : String+ , email : String+ }+init _ =+ ( { users = []+ , inputText = ""+ , error = Nothing+ }+ , fetchUsers+ )+type Msg+ = GotUsers (Result Http.Error (List User))+ | InputChanged String+ | AddUser+ | UserAdded (Result Http.Error User)+update msg model =+ case msg of+ GotUsers result ->+ case result of+ Ok users ->+ ( { model | users = users, error = Nothing }+ , Cmd.none+ )+ Err _ ->+ ( { model | error = Just "Failed to fetch users" }+ , Cmd.none+ )++ InputChanged text ->+ ( { model | inputText = text }+ , Cmd.none+ )++ AddUser ->+ ( model+ , addUser model.inputText+ )++ UserAdded result ->+ case result of+ Ok user ->+ ( { model+ | users = user :: model.users+ , inputText = ""+ , error = Nothing+ }+ , Cmd.none+ )+ Err _ ->+ ( { model | error = Just "Failed to add user" }+ , Cmd.none+ )+fetchUsers =+ Http.get+ { url = "/api/users"+ , expect = Http.expectJson GotUsers usersDecoder+ }+addUser name =+ Http.post+ { url = "/api/users"+ , body = Http.jsonBody (userEncoder name)+ , expect = Http.expectJson UserAdded userDecoder+ }+userEncoder name =+ Encode.object+ [ ("name", Encode.string name)+ ]+userDecoder =+ Decode.map3 User+ (Decode.field "id" Decode.int)+ (Decode.field "name" Decode.string)+ (Decode.field "email" Decode.string)+usersDecoder =+ Decode.list userDecoder+view model =+ div []+ [ h1 [] [ text "User Management" ]+ , viewError model.error+ , viewInput model.inputText+ , viewUsers model.users+ ]+viewError maybeError =+ case maybeError of+ Just error ->+ div [ class "error" ] [ text error ]+ Nothing ->+ text ""+viewInput inputText =+ div []+ [ input+ [ value inputText+ , onInput InputChanged+ , placeholder "Enter user name"+ ] []+ , button [ onClick AddUser ] [ text "Add User" ]+ ]+viewUsers users =+ div []+ [ h2 [] [ text "Users" ]+ , ul [] (List.map viewUser users)+ ]+viewUser user =+ li []+ [ text (user.name ++ " (" ++ user.email ++ ")")+ ]+main =+ Browser.element+ { init = init+ , update = update+ , view = view+ , subscriptions = \_ -> Sub.none+ }++### ../examples/go_example.go+type DataProcessor interface {+type ValidationError struct+func (e *ValidationError) Error() string+type User struct+type UserID = int64+const (+ - MaxRetries+ - DefaultLimit+const+ - singleLineConst string+var (+ - defaultTimeout+ - processor DataProcessor+var+ - singleLineVar string+type Result[T any] struct+type UserProcessor struct+func NewUserProcessor() *UserProcessor+func (p *UserProcessor) Process(ctx context.Context, data interface{}) error+func (p *UserProcessor) Validate(data interface{}) bool+func processUsers(ctx context.Context, users <-chan *User) <-chan *Result[*User]+func createUser(name, email string) (user *User, err error)+func main()++### ../examples/groovy_example.groovy+trait Loggable+abstract class+class Car extends Vehicle implements Loggable {+ // Properties with type definitions+ private BigDecimal price+ protected Boolean running = false++ // Static fields+ static final String MANUFACTURER = "Generic Motors"+ static def carCount = 0++ // Constructor with default parameters+Car(String make = 'Unknown', String model = 'Generic', Integer year = 2024) {+ this.make = make+ this.model = model+ this.year = year+ carCount+++}++ // Getter with @Lazy annotation+ @Lazy+ String fullName = "$make $model ($year)"++ // Method implementation with closure parameter+ void start() {+ running = true+ log "Starting ${fullName}"+ withLock {+ // Some synchronized code+ println "Engine started"+ }+ }++ void stop() {+ running = false+ log "Stopping ${fullName}"+ }++ // Operator overloading+ def plus(Car other) {+ new Car(+make: "${this.make}-${other.make}",+model: "${this.model}-${other.model}",+year: Math.max(this.year, other.year)+ )+ }++ // Property with custom getter/setter+ private BigDecimal _price+ void setPrice(BigDecimal price) {+ if (price < 0) throw new IllegalArgumentException("Price cannot be negative")+ this._price = price+ }+ BigDecimal getPrice() { _price }+}+enum Status+class StringExtensions {+ static String truncate(String self, Integer length) {+ self.size() <= length ? self : self[0..<length] + "..."+ }+}+class EmailBuilder {+ private def email = [:]++ EmailBuilder to(String recipient) {+ email.to = recipient+ this+ }++ EmailBuilder from(String sender) {+ email.from = sender+ this+ }++ EmailBuilder subject(String subject) {+ email.subject = subject+ this+ }++ EmailBuilder body(@DelegatesTo(strategy=Closure.DELEGATE_FIRST) Closure body) {+ def builder = new StringBuilder()+ body.delegate = builder+ body.resolveStrategy = Closure.DELEGATE_FIRST+ body()+ email.body = builder.toString()+ this+ }++ Map build() {+ email.clone() as Map+ }+}+def main() {+ use(StringExtensions) {+ def description = "This is a very long description that needs truncating"+ println description.truncate(20)+ }++ def car = new Car(make: "Tesla", model: "Model S")+ car.start()+def email = new EmailBuilder()+ .to("[email protected]")+ .from("[email protected]")+ .subject("Test Email")+ .body {+ append "Hello,\n"+ append "This is a test email.\n"+ append "Regards"+ }+ .build()+ .build()++ println email+}++### ../examples/java_example.java+interface DataProcessor<T extends Comparable<T>>+ - CompletableFuture<T> processAsync(T input);+ - boolean validate(T input);+enum Status+abstract class BaseEntity<ID>+ - protected ID id+ - protected LocalDateTime createdAt+ - protected LocalDateTime updatedAt+ - public abstract void validate();+record UserDTO(+ String name,+ String email,+ Set<String> roles+)+@interface Audited+public class Example extends BaseEntity<UUID> implements DataProcessor<String>+ - private static final int MAX_RETRIES+ - private static final Map<String, Integer> CACHE+ - private final Queue<String> queue+ - protected Status status+ - @Audited+ public String name+ - private Example(Builder builder)+ - public static class Builder+ - private String name+ - public Builder name(String name)+ - public Example build()+ - @Override+ public CompletableFuture<String> processAsync(String input)+ - @Override+ public boolean validate(String input)+ - @Override+ public void validate()+ - public <T extends Comparable<? super T>> List<T> sort(Collection<T> items)+ - public void processItems(+ List<String> items,+ Predicate<String> filter,+ Consumer<String> processor+ )+ - public static class ProcessingException extends RuntimeException+ - public ProcessingException(String message)+ - public static void main(String[] args)++### ../examples/javascript_example.js+const MAX_RETRIES+const DEFAULT_TIMEOUT+const privateState+class DataProcessor extends EventEmitter+ - #cache+ - static version+ - constructor({ maxRetries = MAX_RETRIES, timeout = DEFAULT_TIMEOUT } = {})+ - async processData(data)+ - async #validateAndTransform(data)+ - *iterateCache()+function deprecated(target, context)+const handler+const proxy+const delay+async function* generateSequence(start, end)+const memoize+class ValidationError extends Error+ - constructor(message, field)+const config+const processItems+const fetchData++### ../examples/kotlin_example.kt+interface DataProcessor<T>+ - suspend fun process(data: T): Result<T>+ - fun validate(data: T): Boolean+sealed class ProcessingState<out T>+ - object Loading : ProcessingState<Nothing>()+ - data class Success<T>(val data: T) : ProcessingState<T>()+ - data class Error(val exception: Throwable) : ProcessingState<Nothing>()+data class User(+ val id: String,+ val name: String,+ val email: String,+ val roles: Set<Role> = emptySet(),+ val createdAt: LocalDateTime = LocalDateTime.now()+)+enum class Role(val permission: Int)+object Configuration+class UserProcessor : DataProcessor<User>+ - private var processingCount: Int by Delegates.observable(0) { _, old, new ->+ println("Processing count changed from $old to $new+ - val isActive: Boolean+ - override suspend fun process(data: User): Result<User>+ - override fun validate(data: User): Boolean+ - private fun String.isValidEmail(): Boolean+ - inline fun <reified T> logType()+ - private fun validateEmail(email: String)+fun <T> withRetry(+ times: Int = 3,+ action: suspend () -> T+): suspend () -> T+fun CoroutineScope.processUsers(users: List<User>): Flow<ProcessingState<User>>+val User.displayName: String+suspend fun main()++### ../examples/lua_example.lua+local Example+local MAX_RETRIES+local DEFAULT_TIMEOUT+local User+local DataStore+local EventEmitter+Example.User+Example.EventEmitter++### ../examples/ocaml_example.ml+type 'a = string+type t = {+ mutable processed_count: int;+ created_at: float;+ }+let create () = {+ processed_count = 0;+ created_at = Unix.time ();+ }+let process t input =+ t.processed_count <- t.processed_count + 1;+ if String.length input > 0 then+ Ok (String.uppercase_ascii input)+ else+ Error "Empty input"+let validate input =+ String.length input > 0+end+type user = {+ id: int;+ name: string;+ email: string;+ created_at: float;+}+type 'a result =+ | Success of 'a+ | Error of string+type message =+ | Text of string+ | Number of int+ | Tuple of string * int+ | Record of user+exception ValidationError of string+let memoize f =+ let cache = Hashtbl.create 16 in+ fun x ->+ try Hashtbl.find cache x+ with Not_found ->+ let result = f x in+ Hashtbl.add cache x result;+ result+class virtual ['a] queue = object(self)+ val mutable items = []++ method virtual push : 'a -> unit+ method virtual pop : 'a option++ method size = List.length items++ method is_empty = items = []++ method protected get_items = items+ method protected set_items new_items = items <- new_items+end+class ['a] fifo_queue = object(self)+ inherit ['a] queue++ method push item =+ self#set_items (self#get_items @ [item])++ method pop =+ match self#get_items with+ | [] -> None+ | hd::tl ->+ self#set_items tl;+ Some hd+end+let () =+ let processor = StringProcessor.create () in+ let result = StringProcessor.process processor "hello world" in+ match result with+ | Ok processed -> Printf.printf "Processed: %s\n" processed+ | Error msg -> Printf.eprintf "Error: %s\n" msg;++ let queue = new fifo_queue in+ queue#push 1;+ queue#push 2;+ queue#push 3;++ let rec print_queue () =+ match queue#pop with+ | Some item ->+ Printf.printf "Item: %d\n" item;+ print_queue ()+ | None -> ()+ in+ print_queue ()++### ../examples/php_example.php+namespace Example;+interface DataProcessor+trait Loggable+abstract class Entity implements JsonSerializable+ - protected DateTime $createdAt+ - protected ?DateTime $updatedAt+ - public function __construct()+ - abstract public function validate(): bool;+ - public function jsonSerialize(): mixed+enum Status: string+class User extends Entity implements DataProcessor+ - private static int $instanceCount+ - public function __construct(+ private string $name,+ private string $email,+ private Status $status = Status::PENDING,+ private array $metadata = []+ )+ - public static function getInstanceCount(): int+ - public function getEmail(): string+ - public function setEmail(string $email): void+ - public function __get(string $name)+ - public function __set(string $name, mixed $value): void+ - public function process(mixed $data): mixed+ - public function validate(mixed $data): bool+ - public function validate(): bool+ - public function getMetadataValues(): array+ - public function jsonSerialize(): mixed+class ProcessingException extends Exception+ - public function __construct(+ string $message = "",+ private ?string $errorCode = null,+ int $code = 0,+ ?Throwable $previous = null+ )+ - public function getErrorCode(): ?string++### ../examples/python_example.py+class Processable(Protocol):+ - def process(self) -> None:+ - def validate(self) -> bool:+class Status(enum.Enum):+ - def __str__(self) -> str:[email protected](frozen=True, slots=True)+class UserCredentials:+class BaseProcessor(ABC, Generic[T]):+ - def __init__(self) -> None:+ - @abstractmethod+ async def process_item(self, item: T) -> None:+ - @property+ def processed_count(self) -> int:+def log_execution(func: Callable) -> Callable:+class DataProcessor(BaseProcessor[UserCredentials], Processable):+ # Class variable+ - def __init__(self, batch_size: Optional[int] = None) -> None:+ - @property+ def status(self) -> Status:+ - @status.setter+ def status(self, value: Status) -> None:+ - async def __aenter__(self) -> DataProcessor:+ - async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:+ - async def process_batch(self) -> AsyncIterator[List[UserCredentials]]:+ - @log_execution+ async def process_item(self, item: UserCredentials) -> None:+ - def process(self) -> None:+ - def validate(self) -> bool:+class ProcessingError(Exception):+ - def __init__(self, message: str, item: Any) -> None:+async def main() -> None:++### ../examples/ruby_example.rb+global_var+module Loggable+ - def log(message)+module Utils+ - class << self+ - def generate_id+class BaseProcessor+ - @processors+ - class << self+ - def register(processor)+ - def initialize+ - def process+class ProcessingError < StandardError+ - def initialize(message, item)+User+module Status+ - PENDING+ - ACTIVE+ - COMPLETED+ - FAILED+ - ALL+class DataProcessor < BaseProcessor+ # Constants+ - MAX_RETRIES+ - DEFAULT_TIMEOUT+ - @@instance_count+ - def initialize(options = {})+ - def add_item(item:, priority: :normal)+ - def validate_item(item)+ - def with_retry+ - def process_items+ - def process_item(item)+class Configuration+ - def initialize+ - def [](key)+ - def []=(key, value)++### ../examples/rust_example.rs+const MAX_RETRIES: u32+const DEFAULT_TIMEOUT: Duration++### ../examples/scala_example.scala+type Result[T] = Either[String, T]+trait DataProcessor[T]+case class ProcessingState[T](+ data: T,+ status: ProcessingState.Status,+ timestamp: Long = System.currentTimeMillis()+)+object ProcessingState+abstract class BaseProcessor[T] extends DataProcessor[T]+ - protected val logger = new Logger(getClass.getName)+ - protected def transform(data: T): T+ - override def process(data: T): Result[T] =+class NumberProcessor[T <: Number] extends BaseProcessor[T]+ - override def validate(data: T): Boolean = data != null+ - protected def transform(data: T): T = data+case class User(+ id: String,+ name: String,+ email: String,+ roles: Set[String] = Set.empty,+ metadata: Map[String, String] = Map.empty+)+object Utils+object Implicits+trait Logging+class Logger(name: String) extends Logging+ - def log(level: String, message: => String): Unit =+trait Monad[F[_]]+object Conversions+trait Container+class Box[T](initial: T) extends Container+ - type Content = T+ - def content: T = initial+ - def transform(f: T => T): Box[T] = new Box(f(initial))+object Main extends App++### ../examples/swift_example.swift+protocol DataProcessor+enum ProcessingError: LocalizedError+ - var errorDescription: String? {+ switch self {+ case .invalidInput(let reason): return "Invalid input: \(reason)"+ case .processingFailed(let reason): return "Processing failed: \(reason)"+ }+ }+@propertyWrapper+struct Validated<T>+ - private var value: T+ - private let validator: (T) -> Bool+ - var wrappedValue: T {+ get { value }+ set {+ guard validator(newValue) else {+ fatalError("Invalid value")+ }+ value = newValue+ }+ }+ - init(wrappedValue: T, validator: @escaping (T) -> Bool)+actor ProcessingState+ - private(set) var processedCount: Int = 0+ - private var status: Status = .pending+ - enum Status+ - func incrementCount()+ - func updateStatus(_ newStatus: Status)+struct Queue<Element> where Element: Sendable+ - private var elements: [Element] = []+ - private let lock = NSLock()+ - mutating func enqueue(_ element: Element)+ - mutating func dequeue() -> Element?+class StringProcessor: DataProcessor+ - typealias Input = String+ - typealias Output = String+ - private let state = ProcessingState()+ - @Validated(validator: { !$0.isEmpty })+ private var currentInput: String = "default"+ - func process(_ input: String) async throws -> String+ - func validate(_ input: String) -> Bool+extension StringProcessor: AsyncSequence, AsyncIteratorProtocol+ - typealias Element = String+ - func makeAsyncIterator() -> StringProcessor+ - func next() async throws -> String?+@resultBuilder+struct ArrayBuilder<T>+ - static func buildBlock(_ components: T...) -> [T]+func makeArray<T>(@ArrayBuilder<T> content: () -> [T]) -> [T]+@main+struct Example+ - static func main() async throws++### ../examples/tsx_example.tsx+interface User+type ValidationResult+interface DataListProps<T>+function useDebounce<T>(value: T, delay: number): T+function withLoading<P extends object>(+ WrappedComponent: React.ComponentType<P>+): FC<P & { loading?: boolean }>+const UserForm: FC<{ onSubmit: (user: Partial<User>) => void }>+const DataList+const App: FC++### ../examples/typescript_example.ts+interface DataProcessor<T>+type Result<T>+enum Status+type ValidationResult+type AdminUser+type Readonly<T>+type Partial<T>+function validate(target: any, propertyKey: string, descriptor: PropertyDescriptor)+@logger+class User+ - @required+ private name: string+ private email: string+ - @format('YYYY-MM-DD')+ private createdAt: Date+ - constructor(name: string, email: string)+ - public updateEmail(newEmail: string): void+ - public get isAdmin(): this is AdminUser+abstract class BaseProcessor<T> implements DataProcessor<T>+class StringProcessor extends BaseProcessor<string>+ - async process(data: string): Promise<string>+ - private async transform(data: string): Promise<string>+function process(data: string): Promise<string>;+function process(data: number): Promise<number>;+function process(data: string | number): Promise<string | number>+async function validateData<T extends { id: string }>(+ data: T+): Promise<ValidationResult>+function withRetry<T>(+ fn: () => Promise<T>,+ retries: number = 3+): () => Promise<T>+type Middleware+const createUser+async function* generateSequence(+ start: number,+ end: number+): AsyncGenerator<number>+async function main()+diff --git a/app/server/syntax/map_examples/elixir_example.ex b/app/server/syntax/map_examples/elixir_example.exdeleted file mode 100644index 9fdd58b2..00000000--- a/app/server/syntax/map_examples/elixir_example.ex+++ /dev/null@@ -1,99 +0,0 @@-defmodule ExampleApp do- # Module attributes (constants)- @default_timeout 5000- @version "1.0.0"-- # Type specifications- @type user :: %{- id: integer,- name: String.t(),- email: String.t(),- roles: [atom]- }-- # Struct definition- defstruct name: "", age: 0, email: nil-- # Behaviour definition- @callback process(term) :: {:ok, term} | {:error, term}-- # Protocol implementation- defimpl String.Chars, for: ExampleApp do- def to_string(%{name: name}), do: "ExampleApp: #{name}"- end-- # Public function with guards- def calculate_age(birth_year) when is_integer(birth_year) do- current_year = DateTime.utc_now().year- current_year - birth_year- end-- # Private function- defp validate_email(email) do- String.match?(email, ~r/^[^\s]+@[^\s]+\.[^\s]+$/)- end-- # Function with pattern matching- def handle_result({:ok, value}), do: "Success: #{value}"- def handle_result({:error, reason}), do: "Error: #{reason}"- def handle_result(_), do: "Unknown result"-- # Macro definition- defmacro debug(expression) do- quote do- IO.puts "Debug: #{inspect(unquote(expression))}"- end- end-- # Using with for complex operations- def create_user(params) do- with {:ok, name} <- Map.fetch(params, "name"),- {:ok, email} <- Map.fetch(params, "email"),- true <- validate_email(email) do- %ExampleApp{name: name, email: email}- else- :error -> {:error, "Missing required fields"}- false -> {:error, "Invalid email format"}- end- end-- # GenServer implementation- use GenServer-- def start_link(opts \\ []) do- GenServer.start_link(__MODULE__, opts, name: __MODULE__)- end-- @impl true- def init(opts) do- {:ok, opts}- end-- @impl true- def handle_call({:get_info}, _from, state) do- {:reply, state, state}- end-- @impl true- def handle_cast({:update_info, new_info}, _state) do- {:noreply, new_info}- end-- # Using comprehensions- def process_list(items) do- for item <- items,- is_binary(item),- String.length(item) > 0,- do: String.upcase(item)- end-- # Exception definition- defmodule CustomError do- defexception message: "A custom error occurred"- end-- # Function raising custom exception- def raise_custom_error do- raise CustomError, message: "Something went wrong"- end-enddiff --git a/app/server/syntax/map_examples/groovy_example.groovy b/app/server/syntax/map_examples/groovy_example.groovydeleted file mode 100644index d85fcc2b..00000000--- a/app/server/syntax/map_examples/groovy_example.groovy+++ /dev/null@@ -1,161 +0,0 @@-#!/usr/bin/env groovy--// Trait definition-trait Loggable {- def log(String message) {- println "[${new Date()}] $message"- }-}--// Abstract class-abstract class Vehicle {- String make- String model- Integer year-- abstract void start()- abstract void stop()-}--// Class with trait implementation-class Car extends Vehicle implements Loggable {- // Properties with type definitions- private BigDecimal price- protected Boolean running = false-- // Static fields- static final String MANUFACTURER = "Generic Motors"- static def carCount = 0-- // Constructor with default parameters-Car(String make = 'Unknown', String model = 'Generic', Integer year = 2024) {- this.make = make- this.model = model- this.year = year- carCount++-}-- // Getter with @Lazy annotation- @Lazy- String fullName = "$make $model ($year)"-- // Method implementation with closure parameter- void start() {- running = true- log "Starting ${fullName}"- withLock {- // Some synchronized code- println "Engine started"- }- }-- void stop() {- running = false- log "Stopping ${fullName}"- }-- // Operator overloading- def plus(Car other) {- new Car(-make: "${this.make}-${other.make}",-model: "${this.model}-${other.model}",-year: Math.max(this.year, other.year)- )- }-- // Property with custom getter/setter- private BigDecimal _price- void setPrice(BigDecimal price) {- if (price < 0) throw new IllegalArgumentException("Price cannot be negative")- this._price = price- }- BigDecimal getPrice() { _price }-}--// Enum definition-enum Status {-ACTIVE('A'),-INACTIVE('I'),-PENDING('P')-- final String code-- private Status(String code) {- this.code = code- }-- String toString() { code }-}--// Category class-class StringExtensions {- static String truncate(String self, Integer length) {- self.size() <= length ? self : self[0..<length] + "..."- }-}--// Builder pattern using closure-class EmailBuilder {- private def email = [:]-- EmailBuilder to(String recipient) {- email.to = recipient- this- }-- EmailBuilder from(String sender) {- email.from = sender- this- }-- EmailBuilder subject(String subject) {- email.subject = subject- this- }-- EmailBuilder body(@DelegatesTo(strategy=Closure.DELEGATE_FIRST) Closure body) {- def builder = new StringBuilder()- body.delegate = builder- body.resolveStrategy = Closure.DELEGATE_FIRST- body()- email.body = builder.toString()- this- }-- Map build() {- email.clone() as Map- }-}--// Main script execution-def main() {- use(StringExtensions) {- def description = "This is a very long description that needs truncating"- println description.truncate(20)- }-- def car = new Car(make: "Tesla", model: "Model S")- car.start()-def email = new EmailBuilder()- .to("[email protected]")- .from("[email protected]")- .subject("Test Email")- .body {- append "Hello,\n"- append "This is a test email.\n"- append "Regards"- }- .build()- .build()-- println email-}--if (this.metaClass.getMetaProperty('main')) {- main()-}- main()-}-}--diff --git a/app/server/syntax/parsers.go b/app/server/syntax/parsers.goindex 2451523a..8d7f45b2 100644--- a/app/server/syntax/parsers.go+++ b/app/server/syntax/parsers.go@@ -42,18 +42,18 @@ func GetParserForExt(ext string) (*tree_sitter.Parser, shared.TreeSitterLanguagereturn nil, "", nil, ""}- parser := getParserForLanguage(lang)+ parser := GetParserForLanguage(lang)fallback := shared.TreeSitterLanguageFallbackByExtension[ext]var fallbackParser *tree_sitter.Parserif fallback != "" {- fallbackParser = getParserForLanguage(fallback)+ fallbackParser = GetParserForLanguage(fallback)}return parser, lang, fallbackParser, fallback}-func getParserForLanguage(lang shared.TreeSitterLanguage) *tree_sitter.Parser {+func GetParserForLanguage(lang shared.TreeSitterLanguage) *tree_sitter.Parser {parser := tree_sitter.NewParser()switch lang {case shared.TreeSitterLanguageBash:diff --git a/app/server/syntax/structural_edits_test.go b/app/server/syntax/structural_edits_test.goindex b408b99d..7c6e0c59 100644--- a/app/server/syntax/structural_edits_test.go+++ b/app/server/syntax/structural_edits_test.go@@ -52,7 +52,7 @@ func TestStructuralReplacements(t *testing.T) {return nil}`,language: shared.TreeSitterLanguageGo,- parser: getParserForLanguage("go"),+ parser: GetParserForLanguage("go"),},{name: "bad formatting",@@ -85,7 +85,7 @@ func TestStructuralReplacements(t *testing.T) {return update(id)}`,language: shared.TreeSitterLanguageGo,- parser: getParserForLanguage("go"),+ parser: GetParserForLanguage("go"),},{name: "multiple refs in class/nested structures",@@ -175,7 +175,7 @@ func TestStructuralReplacements(t *testing.T) {}`,language: shared.TreeSitterLanguageGo,- parser: getParserForLanguage("go"),+ parser: GetParserForLanguage("go"),},{name: "code removal comment",@@ -210,7 +210,7 @@ func TestStructuralReplacements(t *testing.T) {return nil}`,language: shared.TreeSitterLanguageGo,- parser: getParserForLanguage("go"),+ parser: GetParserForLanguage("go"),},{name: "multiple code removal comments",@@ -247,7 +247,7 @@ func TestStructuralReplacements(t *testing.T) {return nil}`,language: shared.TreeSitterLanguageGo,- parser: getParserForLanguage("go"),+ parser: GetParserForLanguage("go"),},{name: "json update with reference comments",@@ -296,7 +296,7 @@ func TestStructuralReplacements(t *testing.T) {}}`,language: shared.TreeSitterLanguageJson,- parser: getParserForLanguage("json"),+ parser: GetParserForLanguage("json"),},{name: "method replacement with context",@@ -366,7 +366,7 @@ func TestStructuralReplacements(t *testing.T) {}}`,language: shared.TreeSitterLanguageJavascript,- parser: getParserForLanguage("javascript"),+ parser: GetParserForLanguage("javascript"),},{name: "nested class methods update",@@ -432,7 +432,7 @@ func TestStructuralReplacements(t *testing.T) {}}`,language: shared.TreeSitterLanguageTypescript,- parser: getParserForLanguage("typescript"),+ parser: GetParserForLanguage("typescript"),},{name: "update with trailing commas",@@ -474,7 +474,7 @@ func TestStructuralReplacements(t *testing.T) {},}`,language: shared.TreeSitterLanguageJavascript,- parser: getParserForLanguage("javascript"),+ parser: GetParserForLanguage("javascript"),},{name: "multiple structural updates",@@ -552,7 +552,7 @@ func TestStructuralReplacements(t *testing.T) {}}`,language: shared.TreeSitterLanguageJavascript,- parser: getParserForLanguage("javascript"),+ parser: GetParserForLanguage("javascript"),},{name: "updated variable assignment",@@ -580,7 +580,7 @@ func TestStructuralReplacements(t *testing.T) {const c = 3;`,language: shared.TreeSitterLanguageJavascript,- parser: getParserForLanguage("javascript"),+ parser: GetParserForLanguage("javascript"),},{@@ -750,7 +750,7 @@ func TestStructuralReplacements(t *testing.T) {}`,language: shared.TreeSitterLanguageJson,- parser: getParserForLanguage("json"),+ parser: GetParserForLanguage("json"),references: []Reference{3, 24, 26,},@@ -972,7 +972,7 @@ func TestStructuralReplacements(t *testing.T) {}`,language: shared.TreeSitterLanguageJson,- parser: getParserForLanguage("json"),+ parser: GetParserForLanguage("json"),references: []Reference{3, 6, 19, 22,},@@ -1102,7 +1102,7 @@ class MetricsService(references: []Reference{4, 7, 13, 26,},- parser: getParserForLanguage("scala"),+ parser: GetParserForLanguage("scala"),},{@@ -1175,7 +1175,7 @@ class MetricsService(return "something"}`,- parser: getParserForLanguage("javascript"),+ parser: GetParserForLanguage("javascript"),},{@@ -1258,7 +1258,7 @@ class MetricsService(return "something"}`,- parser: getParserForLanguage("javascript"),+ parser: GetParserForLanguage("javascript"),},}diff --git a/app/server/types/active_plan.go b/app/server/types/active_plan.goindex 4cedf7eb..cc0b909f 100644--- a/app/server/types/active_plan.go+++ b/app/server/types/active_plan.go@@ -351,6 +351,9 @@ func (sub *subscription) enqueueMessage(msg string) {}func (ap *ActivePlan) ShouldVerifyDiff() bool {+ // disabling tell-based verifications for now+ return false+// log.Printf("ShouldVerifyDiff: buildOnly=%v, didVerifyDiff=%v, numBuiltFiles=%d, didEditFiles=%v, hasMultipleBuiltFiles=%v",// !ap.BuildOnly,// !ap.DidVerifyDiff,@@ -358,11 +361,11 @@ func (ap *ActivePlan) ShouldVerifyDiff() bool {// ap.DidEditFiles,// len(ap.BuiltFiles) > 3)- return !ap.BuildOnly &&- !ap.IsVerifyingDiff &&- !ap.DidVerifyDiff &&- (len(ap.BuiltFiles) > 0 || len(ap.IsBuildingByPath) > 0) &&- (ap.DidEditFiles || len(ap.BuiltFiles) > 3) // verify diff if we edited any files or built more than 3 new files—unlikely to have errors otherwise+ // return !ap.BuildOnly &&+ // !ap.IsVerifyingDiff &&+ // !ap.DidVerifyDiff &&+ // (len(ap.BuiltFiles) > 0 || len(ap.IsBuildingByPath) > 0) &&+ // (ap.DidEditFiles || len(ap.BuiltFiles) > 3) // verify diff if we edited any files or built more than 3 new files—unlikely to have errors otherwise}func (ap *ActivePlan) Finish() {diff --git a/app/server/types/anchors.go b/app/server/types/anchors.goindex f9ffc45d..000df8f0 100644--- a/app/server/types/anchors.go+++ b/app/server/types/anchors.go@@ -17,3 +17,23 @@ type SummaryTag struct {XMLName xml.Name `xml:"PlandexSummary"`Content string `xml:",chardata"`}++type ReferencesTag struct {+ XMLName xml.Name `xml:"PlandexReferences"`+ References []ReferenceTag `xml:"Reference"`+}++type ReferenceTag struct {+ Comment string `xml:"comment,attr"`+ ProposedLine string `xml:"proposedLine,attr"`+}++type RemovalsTag struct {+ XMLName xml.Name `xml:"PlandexRemovals"`+ Removals []RemovalTag `xml:"Removal"`+}++type RemovalTag struct {+ Comment string `xml:"comment,attr"`+ ProposedLine string `xml:"proposedLine,attr"`+}diff --git a/app/server/types/reply.go b/app/server/types/reply.goindex 76a4469a..4b83f509 100644--- a/app/server/types/reply.go+++ b/app/server/types/reply.go@@ -1,7 +1,9 @@package typesimport (+ "log""os"+ "strconv""strings")@@ -47,7 +49,7 @@ func NewReplyParser() *ReplyParser {}func (r *ReplyParser) AddChunk(chunk string, addToTotal bool) {- // log.Println("Adding chunk:", strconv.Quote(chunk)) // Logging the chunk that's being processed+ log.Println("Adding chunk:", strconv.Quote(chunk)) // Logging the chunk that's being processedhasNewLine := falsenextChunk := ""@@ -64,7 +66,7 @@ func (r *ReplyParser) AddChunk(chunk string, addToTotal bool) {}if chunk == "\n" {- // log.Println("Chunk is \\n, adding new line")+ log.Println("Chunk is \\n, adding new line")r.lines = append(r.lines, "")hasNewLine = truer.lineIndex++@@ -122,7 +124,7 @@ func (r *ReplyParser) AddChunk(chunk string, addToTotal bool) {}prevFullLine := r.lines[r.lineIndex-1]- // log.Println("Previous full line:", strconv.Quote(prevFullLine)) // Logging the full line that's being checked+ log.Println("Previous full line:", strconv.Quote(prevFullLine)) // Logging the full line that's being checkedprevFullLineTrimmed := strings.TrimSpace(prevFullLine)@@ -158,7 +160,7 @@ func (r *ReplyParser) AddChunk(chunk string, addToTotal bool) {}if r.currentFilePath == "" {- // log.Println("Current file path is empty--checking for possible file path...")+ log.Println("Current file path is empty--checking for possible file path...")var gotPath stringif lineMaybeHasFilePath(prevFullLineTrimmed) {@@ -176,7 +178,7 @@ func (r *ReplyParser) AddChunk(chunk string, addToTotal bool) {}}} else {- // log.Println("Current file path is not empty--adding to current file...")+ log.Println("Current file path is not empty--adding to current file...")if strings.HasPrefix(prevFullLineTrimmed, "```") {// log.Println("Found closing ticks--adding file to files and resetting current file...")r.files = append(r.files, r.currentFilePath)diff --git a/app/server/types/reply_test.go b/app/server/types/reply_test.goindex df57f7a8..478de555 100644--- a/app/server/types/reply_test.go+++ b/app/server/types/reply_test.go@@ -54,6 +54,12 @@ var examples = []TestExample{"server/model/proposal/create.go": 239,},},+ {+ N: 7,+ TokensByFilePath: map[string]int{+ "file_map/map.go": 239,+ },+ },}func TestReplyTokenCounter(t *testing.T) {@@ -85,7 +91,7 @@ func TestReplyTokenCounter(t *testing.T) {i = end}- res := counter.FinishAndRead()+ res := counter.Read()totalCounted := res.TotalTokensfiles := res.Filesdiff --git a/app/server/types/reply_test_examples/7.md b/app/server/types/reply_test_examples/7.mdnew file mode 100644index 00000000..e0c1d9f6--- /dev/null+++ b/app/server/types/reply_test_examples/7.md@@ -0,0 +1,116 @@+**Updating `file_map/map.go`**: I'll add debug logging to the mapMarkup function between the function declaration and the end of the file.++- file_map/map.go:+```go+// ... existing code ...++func mapMarkup(node *tree_sitter.Node, content []byte) []Definition {+ if verboseLogging {+ fmt.Println("mapMarkup called with node type:", node.Type())+ }++ var defs []Definition+ cursor := tree_sitter.NewTreeCursor(node)+ defer cursor.Close()++ if cursor.GoToFirstChild() {+ if verboseLogging {+ fmt.Println("cursor went to first child")+ }++ for {+ node := cursor.CurrentNode()+ if verboseLogging {+ fmt.Println("processing node type:", node.Type())+ }++ if node.Type() == "element" {+ if verboseLogging {+ fmt.Println("found element node")+ }++ // Get tag name from start_tag+ if startTag := node.ChildByFieldName("start_tag"); startTag != nil {+ if verboseLogging {+ fmt.Println("found start_tag:", startTag.Type())+ }++ if nameNode := startTag.ChildByFieldName("name"); nameNode != nil {+ if verboseLogging {+ fmt.Printf("found name node: %s with content: %s\n",+ nameNode.Type(), string(nameNode.Content(content)))+ }++ def := Definition{+ Type: "tag",+ Line: int(node.StartPoint().Row) + 1,+ Signature: string(nameNode.Content(content)),+ }++ // Get class and id attributes+ var attrs []string+ for i := 0; i < int(startTag.ChildCount()); i++ {+ child := startTag.Child(i)+ if verboseLogging {+ fmt.Printf("checking child %d type: %s\n", i, child.Type())+ }++ if child.Type() == "attribute" {+ if verboseLogging {+ fmt.Println("found attribute node")+ }++ if attrName := child.ChildByFieldName("name"); attrName != nil {+ name := string(attrName.Content(content))+ if verboseLogging {+ fmt.Printf("found attribute name: %s\n", name)+ }++ if name == "class" || name == "id" {+ if attrValue := child.ChildByFieldName("value"); attrValue != nil {+ if verboseLogging {+ fmt.Printf("found attribute value: %s\n",+ string(attrValue.Content(content)))+ }+ attrs = append(attrs, fmt.Sprintf("%s=%q",+ name, attrValue.Content(content)))+ }+ }+ }+ }+ }+ def.TagAttrs = attrs++ // Recursively process children+ if verboseLogging {+ fmt.Println("recursively processing children")+ }+ def.Children = mapMarkup(node, content)+ defs = append(defs, def)+ } else if verboseLogging {+ fmt.Println("no name node found")+ }+ } else if verboseLogging {+ fmt.Println("no start_tag found")+ }+ }++ if !cursor.GoToNextSibling() {+ if verboseLogging {+ fmt.Println("no more siblings")+ }+ break+ }+ }+ } else if verboseLogging {+ fmt.Println("cursor could not go to first child")+ }++ if verboseLogging {+ fmt.Printf("returning %d definitions\n", len(defs))+ }+ return defs+}++// ... existing code ...+```\ No newline at end of filediff --git a/app/shared/syntax.go b/app/shared/syntax.goindex 75c8ecfd..ee2caa72 100644--- a/app/shared/syntax.go+++ b/app/shared/syntax.go@@ -1,5 +1,10 @@package shared+import (+ "path/filepath"+ "strings"+)+type TreeSitterLanguage stringconst (@@ -72,11 +77,31 @@ var TreeSitterLanguages = []TreeSitterLanguage{TreeSitterLanguageYaml,}+var lacksFileMapSupport = []TreeSitterLanguage{+ // config languages aren't mapped, model decides whether to load them based on file name+ TreeSitterLanguageHcl,+ TreeSitterLanguageYaml,+ TreeSitterLanguageToml,+ TreeSitterLanguageCue,+ TreeSitterLanguageJson,+ TreeSitterLanguageProtobuf,++ // these just need more work for mapping+ TreeSitterLanguageGroovy,+ TreeSitterLanguageOCaml,+}+var TreeSitterLanguageSet = map[TreeSitterLanguage]bool{}+var TreeSitterFileMapSupportSet = map[TreeSitterLanguage]bool{}+func init() {for _, lang := range TreeSitterLanguages {TreeSitterLanguageSet[lang] = true+ TreeSitterFileMapSupportSet[lang] = true+ }+ for _, lang := range lacksFileMapSupport {+ TreeSitterFileMapSupportSet[lang] = false}}@@ -84,48 +109,58 @@ func IsTreeSitterLanguage(lang TreeSitterLanguage) bool {return TreeSitterLanguageSet[lang]}-func IsTreeSitterExtension(ext string) bool {- return TreeSitterLanguageByExtension[ext] != ""+func HasTreeSitterSupport(path string) bool {+ base := filepath.Base(path)+ ext := filepath.Ext(base)+ isDockerfile := strings.Contains(strings.ToLower(base), "dockerfile")+ return isDockerfile || TreeSitterLanguageByExtension[ext] != ""+}++func HasFileMapSupport(path string) bool {+ base := filepath.Base(path)+ ext := filepath.Ext(base)+ isDockerfile := strings.Contains(strings.ToLower(base), "dockerfile")+ lang := TreeSitterLanguageByExtension[ext]+ return isDockerfile || (lang != "" && TreeSitterFileMapSupportSet[lang])}var TreeSitterLanguageByExtension = map[string]TreeSitterLanguage{- ".sh": TreeSitterLanguageBash,- ".bash": TreeSitterLanguageBash,- ".c": TreeSitterLanguageC,- ".h": TreeSitterLanguageC,- ".cpp": TreeSitterLanguageCpp,- ".cc": TreeSitterLanguageCpp,- ".cs": TreeSitterLanguageCsharp,- ".css": TreeSitterLanguageCss,- ".cue": TreeSitterLanguageCue,- ".dockerfile": TreeSitterLanguageDockerfile,- ".ex": TreeSitterLanguageElixir,- ".exs": TreeSitterLanguageElixir,- ".elm": TreeSitterLanguageElm,- ".go": TreeSitterLanguageGo,- ".groovy": TreeSitterLanguageGroovy,- ".hcl": TreeSitterLanguageHcl,- ".html": TreeSitterLanguageHtml,- ".java": TreeSitterLanguageJava,- ".js": TreeSitterLanguageJavascript,- ".json": TreeSitterLanguageJson,- ".jsx": TreeSitterLanguageTsx,- ".kt": TreeSitterLanguageKotlin,- ".lua": TreeSitterLanguageLua,- ".ml": TreeSitterLanguageOCaml,- ".php": TreeSitterLanguagePhp,- ".proto": TreeSitterLanguageProtobuf,- ".py": TreeSitterLanguagePython,- ".rb": TreeSitterLanguageRuby,- ".rs": TreeSitterLanguageRust,- ".scala": TreeSitterLanguageScala,- ".svelte": TreeSitterLanguageSvelte,- ".swift": TreeSitterLanguageSwift,- ".toml": TreeSitterLanguageToml,- ".ts": TreeSitterLanguageTypescript,- ".tsx": TreeSitterLanguageTsx,- ".yaml": TreeSitterLanguageYaml,- ".yml": TreeSitterLanguageYaml,+ ".sh": TreeSitterLanguageBash,+ ".bash": TreeSitterLanguageBash,+ ".c": TreeSitterLanguageC,+ ".h": TreeSitterLanguageC,+ ".cpp": TreeSitterLanguageCpp,+ ".cc": TreeSitterLanguageCpp,+ ".cs": TreeSitterLanguageCsharp,+ ".css": TreeSitterLanguageCss,+ ".cue": TreeSitterLanguageCue,+ ".ex": TreeSitterLanguageElixir,+ ".exs": TreeSitterLanguageElixir,+ ".elm": TreeSitterLanguageElm,+ ".go": TreeSitterLanguageGo,+ ".groovy": TreeSitterLanguageGroovy,+ ".hcl": TreeSitterLanguageHcl,+ ".html": TreeSitterLanguageHtml,+ ".java": TreeSitterLanguageJava,+ ".js": TreeSitterLanguageJavascript,+ ".json": TreeSitterLanguageJson,+ ".jsx": TreeSitterLanguageTsx,+ ".kt": TreeSitterLanguageKotlin,+ ".lua": TreeSitterLanguageLua,+ ".ml": TreeSitterLanguageOCaml,+ ".php": TreeSitterLanguagePhp,+ ".proto": TreeSitterLanguageProtobuf,+ ".py": TreeSitterLanguagePython,+ ".rb": TreeSitterLanguageRuby,+ ".rs": TreeSitterLanguageRust,+ ".scala": TreeSitterLanguageScala,+ ".svelte": TreeSitterLanguageSvelte,+ ".swift": TreeSitterLanguageSwift,+ ".toml": TreeSitterLanguageToml,+ ".ts": TreeSitterLanguageTypescript,+ ".tsx": TreeSitterLanguageTsx,+ ".yaml": TreeSitterLanguageYaml,+ ".yml": TreeSitterLanguageYaml,}var TreeSitterLanguageFallbackByExtension = map[string]TreeSitterLanguage{