Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Agent 笔记:在当前工作区完成插件启用

状态:已实现

## 先说结论

工作区推荐里的「查看插件」直接打开插件市场,推荐多项时显示完整目录。启用语言服务器插件后,已打开、语言已识别的文件在原标签开始同步。用户可以在当前项目继续编辑。

## 问题

多项推荐沿用了普通插件设置入口,新窗口显示已安装的插件。打开文件时若没有语言服务器提供者,插件启用后也没有新的打开事件来请求服务器。安装恰好发生在首次查询已读到旧插件列表时,同语言的启动去重还可能吞掉新的请求。

## 决策

插件市场入口显式区分未指定搜索和空搜索。插件状态变更通过现有启动入口处理已打开文件,每种语言最多请求一次。首次启动使用旧列表并且未找到提供者时,才处理期间积存的注册表刷新请求。窗口和项目关闭、用户取消、以及正在运行的会话沿用原生命周期。

## 考虑过的备选方案

等待用户再次打开文件会延迟语言能力。启用任何插件都重启项目语言服务会重复导入工作区,并中断正在运行的会话。已有打开文件提供了按需启动所需的信息。

## 后果

启用后会查询已打开文件对应的语言,有服务的语言可以立即准备。已运行的服务器继续服务,真实启动错误仍通过现有诊断反馈。完全未知扩展名的旧标签需要再次打开来识别语言。

## 验证

运行 `./scripts/desktop/desktop-go.sh test ./internal/workbench -run TestPluginEnable`,覆盖现有文件接管及安装与旧查询交错。运行 `./scripts/desktop/desktop-go.sh test ./internal/settingswindow -run TestOpenMarketplaceWithoutSearch`,覆盖首次打开窗口和窗口已打开两种情况。

## 适用范围

适用于 Viva 工作台的插件管理、现有文档同步和设置窗口的插件市场入口。
18 changes: 6 additions & 12 deletions desktop/internal/settingswindow/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ type Values struct {
EditorPreferences core.EditorPreferences
EditorStoredPreferences core.EditorStoredPreferences
KeymapSchemes core.KeymapSchemes
// MarketplaceQuery is the text the marketplace search starts with when the window opens on
// the plugin page; empty leaves it as it is.
MarketplaceQuery string
// MarketplaceQuery opens the Marketplace with that search. A nil query leaves the tab alone.
MarketplaceQuery *string
// Language is a stored i18n language code ("en", "zh-Hans"); empty follows the system.
Language string
// Theme is "light" or "dark"; empty follows the system's look.
Expand Down Expand Up @@ -657,8 +656,8 @@ func (c *Controller) OpenPlugins(application *app.Application, current Values) e
// OpenPluginsWithQuery shows the plugin page with the marketplace search set to query, which
// is what "Find in Marketplace" asks for; an open window takes the query too.
func (c *Controller) OpenPluginsWithQuery(application *app.Application, current Values, query string) error {
current.MarketplaceQuery = query
return c.openWithQuery(application, current, pagePlugins, query)
current.MarketplaceQuery = &query
return c.open(application, current, pagePlugins)
}

// OpenTerminal opens the Terminal page under Tools, including when a settings window is
Expand Down Expand Up @@ -691,16 +690,11 @@ func (c *Controller) OpenAI(application *app.Application, current Values) error

// open shows the window on page, or, with noPage, on the page it already has or starts on.
func (c *Controller) open(application *app.Application, current Values, page pageID) error {
return c.openWithQuery(application, current, page, "")
}

// openWithQuery is open that also sets the marketplace search to query when it is not empty.
func (c *Controller) openWithQuery(application *app.Application, current Values, page pageID, query string) error {
c.mu.Lock()
if open := c.current; open != nil && open.win != nil && !open.win.Closed() && !open.sess.finished.Load() {
win := open.win
if query != "" {
open.requestQuery(query)
if current.MarketplaceQuery != nil {
open.requestQuery(*current.MarketplaceQuery)
}
if page != noPage {
open.requestPage(page)
Expand Down
23 changes: 23 additions & 0 deletions desktop/internal/settingswindow/marketplace_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,26 @@ func TestMarketplaceShowsFailureError(t *testing.T) {
}
})
}

func TestOpenMarketplaceWithoutSearch(t *testing.T) {
query := ""
w := newWindow(NewController(Options{
Marketplace: func(context.Context) (marketplace.Snapshot, error) {
return marketplace.Snapshot{}, nil
},
}), Values{MarketplaceQuery: &query})
w.sess.show(pagePlugins)
d := openWindow(t, w)
if w.pluginTab != pluginTabMarketplace || w.marketQuery != "" {
t.Fatalf("opened plugins tab = %v, query = %q, want unfiltered Marketplace", w.pluginTab, w.marketQuery)
}

w.pluginTab = pluginTabInstalled
w.marketQuery = "previous query"
w.requestQuery("")
w.requestPage(pagePlugins)
d.pump()
if w.pluginTab != pluginTabMarketplace || w.marketQuery != "" {
t.Fatalf("reopened plugins tab = %v, query = %q, want unfiltered Marketplace", w.pluginTab, w.marketQuery)
}
}
16 changes: 15 additions & 1 deletion desktop/internal/settingswindow/visual_capture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestVisualSettings(t *testing.T) {
{"23-settings-keymap", pageKeymap}, {"24-settings-network", pageNetwork},
{"25-settings-process", pageProcessTermination}, {"26-settings-git", pageVersionControl}, {"26-settings-git-console", pageVersionControl},
{"27-settings-terminal", pageTerminal}, {"28-plugins-installed", pagePlugins},
{"29-marketplace-empty", pagePlugins},
{"29-marketplace-empty", pagePlugins}, {"29-marketplace-recommendations", pagePlugins},
{"32-settings-build", pageBuild}, {"32-settings-build-kind", pageBuild}, {"34-settings-debuggers", pageDebuggers},
{"33-settings-toolchains", pageToolchains}, {"m44-toolchain-directory-menu", pageToolchains}, {"m45-toolchain-custom-directory", pageToolchains},
{"m47-toolchain-project-untrusted", pageToolchains}, {"m48-toolchain-project-trusted", pageToolchains}, {"m49-toolchain-project-trust-click", pageToolchains},
Expand Down Expand Up @@ -99,6 +99,17 @@ func TestVisualSettings(t *testing.T) {
}
opts.SetAutoUpdatePlugins = func(bool) {}
values := Values{Theme: theme, Language: language.Code(), TerminalScrollback: 2000, AutoUpdatePlugins: scenario.id == "m42-plugin-auto-update-on"}
if scenario.id == "29-marketplace-recommendations" {
query := ""
values.MarketplaceQuery = &query
opts.Marketplace = func(context.Context) (marketplace.Snapshot, error) {
return marketplace.Snapshot{Index: core.MarketplaceIndex{Plugins: []core.MarketplacePlugin{
{ID: "dev.lithe.test.demo-build", Name: "Demo Build", Availability: core.MarketplaceAvailability{Status: "available", Version: "1.0.0"}},
{ID: "dev.lithe.test.demo-language", Name: "Demo Language", Availability: core.MarketplaceAvailability{Status: "available", Version: "1.0.0"}},
}}}, nil
}
opts.PluginState = nil
}
if scenario.page == pageBuild || scenario.page == pageDebuggers {
values.SteppingFilters = map[string]core.DebugSteppingFilters{"fixture-jvm": {ClassNameFilters: []string{"java.*", "javax.*", "sun.*", "com.example.generated.*"}, SkipSynthetics: true, SkipStaticInitializers: true}}
}
Expand All @@ -115,6 +126,9 @@ func TestVisualSettings(t *testing.T) {
}
w := newWindow(NewController(opts), values)
w.sess.page = scenario.page
if scenario.id == "29-marketplace-recommendations" && (w.pluginTab != pluginTabMarketplace || w.marketQuery != "") {
t.Fatal("recommendations must open the unfiltered Marketplace")
}
if scenario.page == pageBuild || parents[scenario.page] == pageBuild {
// As the Build page opens its pages: with the group open in the sidebar.
w.sess.open[pageBuild] = true
Expand Down
4 changes: 2 additions & 2 deletions desktop/internal/settingswindow/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ func newWindow(c *Controller, current Values) *window {
w.market.setCustom(c.opts.MarketplaceSources)
w.market.reportDiscarded = c.opts.MarketplaceError
w.market.search.rank = c.opts.MarketplaceRank
w.marketQuery = current.MarketplaceQuery
if w.marketQuery != "" {
if current.MarketplaceQuery != nil {
w.marketQuery = *current.MarketplaceQuery
w.pluginTab = pluginTabMarketplace
}
w.market.search.report = c.opts.MarketplaceError
Expand Down
12 changes: 5 additions & 7 deletions desktop/internal/workbench/plugin_recommendations.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,19 +354,17 @@ func (a *App) notifyPluginRecommendations(root string, recommendations []core.Ma
})
primaryLabel := i18n.Shared(language, "desktop.marketplace.recommendedAction")
secondaryLabel := i18n.Shared(language, "desktop.marketplace.recommendedDismiss")
firstQuery := names[0]
multiple := len(filtered) > 1
query := ""
if len(names) == 1 {
query = names[0]
}
a.shownTab().notifyActions(
title,
detail,
ui.ToastInfo,
primaryLabel,
func(target *App) {
if multiple {
target.openPluginSettings(surfaceNotification)
return
}
target.openPluginSettingsSearch(surfaceNotification, firstQuery)
target.openPluginSettingsSearch(surfaceNotification, query)
},
secondaryLabel,
func(target *App) {
Expand Down
27 changes: 20 additions & 7 deletions desktop/internal/workbench/pluginbackends.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
// Progress is written by the worker and read by the status bar; identity and
// cancellation remain protected by pluginServerMu.
type pluginServerPreparation struct {
project *project
cancel context.CancelFunc
progress atomic.Pointer[pluginruntime.Progress]
cancelled atomic.Bool
pluginID string
revision uint64
project *project
cancel context.CancelFunc
progress atomic.Pointer[pluginruntime.Progress]
cancelled atomic.Bool
pluginID string
revision uint64
retryWithoutProvider bool
}

func (p *pluginServerPreparation) stop() {
Expand Down Expand Up @@ -182,6 +183,10 @@ func (s *pluginServer) endBuild() {
// A language nothing serves is the ordinary case for most files, so a missing
// provider is not an error and nothing is logged for it.
func (a *App) startPluginServer(languageID string) {
a.requestPluginServer(languageID, false)
}

func (a *App) requestPluginServer(languageID string, providersChanged bool) {
if a.plugins == nil || languageID == "" {
return
}
Expand All @@ -197,7 +202,11 @@ func (a *App) startPluginServer(languageID string) {
}
if a.pluginServerStarting[languageID] {
// Opening several files of one language at once must not launch several
// servers; the first start answers for all of them.
// servers. A registry change can arrive after this start read the
// old registry, so repeat selection if it returns without a provider.
if preparation := a.pluginServerPreparations[languageID]; providersChanged && preparation != nil {
preparation.retryWithoutProvider = true
}
a.pluginServerMu.Unlock()
return
}
Expand Down Expand Up @@ -259,6 +268,7 @@ func (a *App) finishPluginServerPreparation(preparation *pluginServerPreparation
owner = session.PluginID
}
changed := a.pluginServerChanges[owner] > preparation.revision
retryWithoutProvider := preparation.retryWithoutProvider
if current {
delete(a.pluginServerPreparations, languageID)
}
Expand All @@ -280,6 +290,9 @@ func (a *App) finishPluginServerPreparation(preparation *pluginServerPreparation
session, err = nil, context.Canceled
}
a.finishPluginServerStart(preparation.project, languageID, pluginID, version, session, err)
if retryWithoutProvider && session == nil && err == nil && a.project == preparation.project {
a.startPluginServer(languageID)
}
}

// finishPluginServerStart takes the started session back on the window thread and
Expand Down
15 changes: 12 additions & 3 deletions desktop/internal/workbench/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (a *App) commitPluginInstall(ctx context.Context, plan plugininstall.Plan,
}

// applyPluginLifecycleChange updates plugin state across every tab and, when reload is
// true, clears stale build state, reloads languages and re-detects builds on open tabs.
// true, reloads languages and refreshes build and language services in open projects.
func (a *App) applyPluginLifecycleChange(reload bool) {
for _, tab := range a.everyTab() {
if reload {
Expand All @@ -267,8 +267,17 @@ func (a *App) applyPluginLifecycleChange(reload bool) {
}
if reload {
for _, tab := range a.openTabs() {
if tab.project != nil {
tab.loadBuildSystems(tab.project)
if p := tab.project; p != nil {
tab.loadBuildSystems(p)
// Opening a file normally requests its server. A plugin installed
// later must also get the files that were already open.
languages := make(map[string]bool)
for _, d := range p.docs.list {
if !d.virtual && !d.scratch && d.languageID != "" && !languages[d.languageID] {
languages[d.languageID] = true
tab.requestPluginServer(d.languageID, true)
}
}
}
}
}
Expand Down
64 changes: 64 additions & 0 deletions desktop/internal/workbench/pluginsync_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,67 @@ func TestClangdBuildStartedSessionSynchronizesEditor(t *testing.T) {
t.Fatal("shared server survived project close")
}
}

func TestPluginEnableStartsServerForOpenDocument(t *testing.T) {
h := clangdHarness(t)
pluginID := "dev.lithe.test.clangd"
if err := h.app.plugins.Manager.SetEnabled(pluginID, false); err != nil {
t.Fatal(err)
}
root := t.TempDir()
path := filepath.Join(root, "open.c")
if err := os.WriteFile(path, []byte("int main(void) { return 0; }\n"), 0o600); err != nil {
t.Fatal(err)
}
h.open(root)
p := h.app.project
h.app.openFile(p, path)
h.settle()
doc := p.docs.byPath(path)
if doc == nil || doc.languageID != "c" || doc.sync.opened {
t.Fatal("expected the existing document to have the bundled language and no server")
}
h.app.setPluginEnabled(pluginID, true)
awaitStateWithin(t, h, 5*time.Second, "the server to open the existing document", func() bool {
return doc.sync.opened && doc.sync.pluginID == pluginID
})
if p.docs.byPath(path) != doc {
t.Fatal("the original document was replaced")
}
}

func TestPluginEnableRetriesAnInFlightStartWithoutProvider(t *testing.T) {
h := clangdHarness(t)
a := h.app
const pluginID = "dev.lithe.test.clangd"
if err := a.plugins.Manager.SetEnabled(pluginID, false); err != nil {
t.Fatal(err)
}
root := t.TempDir()
path := filepath.Join(root, "open.c")
if err := os.WriteFile(path, []byte("int main(void) { return 0; }\n"), 0o600); err != nil {
t.Fatal(err)
}
h.open(root)
p := a.project
a.openFile(p, path)
h.settle()
doc := p.docs.byPath(path)
if doc == nil || doc.languageID != "c" || doc.sync.opened {
t.Fatal("expected the file open without an enabled provider")
}

// The first start inspected the disabled registry. Hold its empty result
// until after the plugin lifecycle callback requests the server again.
attempt := &pluginServerPreparation{project: p, cancel: func() {}}
a.pluginServerPreparations["c"] = attempt
a.pluginServerStarting["c"] = true
if err := a.plugins.Manager.SetEnabled(pluginID, true); err != nil {
t.Fatal(err)
}
a.applyPluginLifecycleChange(true)
a.finishPluginServerPreparation(attempt, "c", "", "", nil, nil)
awaitStateWithin(t, h, 5*time.Second, "the enabled server to open the existing document", func() bool {
return doc.sync.opened && doc.sync.pluginID == pluginID
})
}
13 changes: 6 additions & 7 deletions desktop/internal/workbench/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func (a *App) openPluginSettings(surface actionSurface) {

// openPluginSettingsSearch shows the plugin page with the marketplace search set to query.
func (a *App) openPluginSettingsSearch(surface actionSurface, query string) {
a.openSettingsPageWith(surface, settingsPlugins, query)
a.openSettingsPageWith(surface, settingsMarketplace, query)
}

// openTerminalSettings shows the settings window on its Terminal page, where the shell new
Expand All @@ -401,6 +401,7 @@ const (
// settingsHome opens the window where it was left, or on its first page.
settingsHome settingsPage = iota
settingsPlugins
settingsMarketplace
settingsTerminal
// settingsAI is the AI page, where the providers a commit message is generated with are
// configured.
Expand Down Expand Up @@ -428,7 +429,7 @@ func (a *App) openSettingsPageWith(surface actionSurface, page settingsPage, que
if a.application == nil {
return
}
if page == settingsPlugins {
if page == settingsPlugins || page == settingsMarketplace {
a.reloadPluginLanguages()
}
a.post(func(a *App) {
Expand Down Expand Up @@ -464,11 +465,9 @@ func (a *App) openSettingsPageWith(surface actionSurface, page settingsPage, que
var err error
switch page {
case settingsPlugins:
if query != "" {
err = a.settingsWindow.OpenPluginsWithQuery(a.application, current, query)
} else {
err = a.settingsWindow.OpenPlugins(a.application, current)
}
err = a.settingsWindow.OpenPlugins(a.application, current)
case settingsMarketplace:
err = a.settingsWindow.OpenPluginsWithQuery(a.application, current, query)
case settingsTerminal:
err = a.settingsWindow.OpenTerminal(a.application, current)
case settingsKeymap:
Expand Down
Loading
Loading