Skip to content

Commit 01f8d3b

Browse files
author
Frank
committed
wip: vscode extension
1 parent 99d6a28 commit 01f8d3b

File tree

4 files changed

+65
-131
lines changed

4 files changed

+65
-131
lines changed

packages/tui/internal/components/commands/commands.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/sst/opencode/internal/commands"
1212
"github.com/sst/opencode/internal/styles"
1313
"github.com/sst/opencode/internal/theme"
14+
"github.com/sst/opencode/internal/util"
1415
)
1516

1617
type CommandsComponent interface {
@@ -24,6 +25,7 @@ type commandsComponent struct {
2425
width, height int
2526
showKeybinds bool
2627
showAll bool
28+
showVscode bool
2729
background *compat.AdaptiveColor
2830
limit *int
2931
}
@@ -73,6 +75,30 @@ func (c *commandsComponent) View() string {
7375
commandsToShow = commandsToShow[:*c.limit]
7476
}
7577

78+
if c.showVscode {
79+
commandsToShow = append(commandsToShow,
80+
// empty line
81+
commands.Command{
82+
Name: "",
83+
Description: "",
84+
},
85+
commands.Command{
86+
Name: commands.CommandName(util.Ide()),
87+
Description: "open opencode",
88+
Keybindings: []commands.Keybinding{
89+
{Key: "cmd+esc", RequiresLeader: false},
90+
},
91+
},
92+
commands.Command{
93+
Name: commands.CommandName(util.Ide()),
94+
Description: "reference file",
95+
Keybindings: []commands.Keybinding{
96+
{Key: "cmd+opt+k", RequiresLeader: false},
97+
},
98+
},
99+
)
100+
}
101+
76102
if len(commandsToShow) == 0 {
77103
muted := styles.NewStyle().Foreground(theme.CurrentTheme().TextMuted())
78104
if c.showAll {
@@ -196,6 +222,12 @@ func WithShowAll(showAll bool) Option {
196222
}
197223
}
198224

225+
func WithVscode(showVscode bool) Option {
226+
return func(c *commandsComponent) {
227+
c.showVscode = showVscode
228+
}
229+
}
230+
199231
func New(app *app.App, opts ...Option) CommandsComponent {
200232
c := &commandsComponent{
201233
app: app,

packages/tui/internal/components/ide/ide.go

Lines changed: 0 additions & 112 deletions
This file was deleted.

packages/tui/internal/tui/tui.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
cmdcomp "github.com/sst/opencode/internal/components/commands"
2525
"github.com/sst/opencode/internal/components/dialog"
2626
"github.com/sst/opencode/internal/components/fileviewer"
27-
"github.com/sst/opencode/internal/components/ide"
2827
"github.com/sst/opencode/internal/components/modal"
2928
"github.com/sst/opencode/internal/components/status"
3029
"github.com/sst/opencode/internal/components/toast"
@@ -654,14 +653,16 @@ func (a Model) home() string {
654653

655654
// Use limit of 4 for vscode, 6 for others
656655
limit := 6
657-
if os.Getenv("OPENCODE_CALLER") == "vscode" {
656+
if util.IsVSCode() {
658657
limit = 4
659658
}
660659

660+
showVscode := util.IsVSCode()
661661
commandsView := cmdcomp.New(
662662
a.app,
663663
cmdcomp.WithBackground(t.Background()),
664664
cmdcomp.WithLimit(limit),
665+
cmdcomp.WithVscode(showVscode),
665666
)
666667
cmds := lipgloss.PlaceHorizontal(
667668
effectiveWidth,
@@ -670,30 +671,13 @@ func (a Model) home() string {
670671
styles.WhitespaceStyle(t.Background()),
671672
)
672673

673-
// Add VSCode shortcuts if in VSCode environment
674-
var ideShortcuts string
675-
if os.Getenv("OPENCODE_CALLER") == "vscode" {
676-
ideView := ide.New()
677-
ideView.SetBackgroundColor(t.Background())
678-
ideShortcuts = lipgloss.PlaceHorizontal(
679-
effectiveWidth,
680-
lipgloss.Center,
681-
ideView.View(),
682-
styles.WhitespaceStyle(t.Background()),
683-
)
684-
}
685-
686674
lines := []string{}
687675
lines = append(lines, "")
688676
lines = append(lines, "")
689677
lines = append(lines, logoAndVersion)
690678
lines = append(lines, "")
691679
lines = append(lines, "")
692680
lines = append(lines, cmds)
693-
if os.Getenv("OPENCODE_CALLER") == "vscode" {
694-
lines = append(lines, "")
695-
lines = append(lines, ideShortcuts)
696-
}
697681
lines = append(lines, "")
698682
lines = append(lines, "")
699683

packages/tui/internal/util/ide.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package util
2+
3+
import (
4+
"os"
5+
"strings"
6+
)
7+
8+
var SUPPORTED_IDES = []struct {
9+
Search string
10+
ShortName string
11+
}{
12+
{"Windsurf", "Windsurf"},
13+
{"Visual Studio Code", "VS Code"},
14+
{"Cursor", "Cursor"},
15+
{"VSCodium", "VSCodium"},
16+
}
17+
18+
func IsVSCode() bool {
19+
return os.Getenv("OPENCODE_CALLER") == "vscode"
20+
}
21+
22+
func Ide() string {
23+
for _, ide := range SUPPORTED_IDES {
24+
if strings.Contains(os.Getenv("GIT_ASKPASS"), ide.Search) {
25+
return ide.ShortName
26+
}
27+
}
28+
29+
return "unknown"
30+
}

0 commit comments

Comments
 (0)