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
148 changes: 116 additions & 32 deletions desktop/internal/i18n/shared.generated.go

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion desktop/internal/workbench/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ func (a *App) openRemote(surface actionSurface) {
r.form.clear()
a.performed("remote.connections.open", surface)
a.loadRemote(remoteLoadSelectFirst, "")
a.loadRemoteImportCounts()
}

// closeRemote closes the window, stopping a running test or connection and ending the session a
Expand Down Expand Up @@ -220,6 +219,9 @@ func (a *App) loadRemote(how remoteLoad, id string) {
if err != nil {
a.operationFailed("remote_connections_read", documentLogError(err))
r.readErr = remoteReadFailure(a.language(), source, err)
} else {
// The counts leave out the hosts already saved, so they follow every reread.
a.loadRemoteImportCounts()
}
switch how {
case remoteLoadKeepForm:
Expand Down Expand Up @@ -337,6 +339,9 @@ func (r *remoteState) editingForm() bool {
// newRemote starts a new connection; Cancel goes back to the one selected before.
func (a *App) newRemote() {
r := &a.remote
if !a.leaveRemoteFlows() {
return
}
a.performed("remote.connection.new", surfaceButton)
if r.selected != "" {
r.previous = r.selected
Expand Down Expand Up @@ -637,6 +642,7 @@ func (a *App) editRemote(site string, edit core.RemoteConnectionEdit) {
}
r.loaded = true
r.setSource(after)
a.loadRemoteImportCounts()
if edit.Remove != nil {
r.selectFirst()
return
Expand Down
96 changes: 82 additions & 14 deletions desktop/internal/workbench/remote_browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"slices"
"strconv"
"strings"
"sync"

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
Expand All @@ -34,17 +35,21 @@ type remoteBrowser struct {
name string
connection core.SSHConnection
// recent are the connection's recent folders, latest first.
recent []string
recentList ui.ListState
recent []string
// path is what the path field holds. dir is the folder listed last, or tried last when it
// could not be listed; folders are its subfolders' names, links to folders among them.
// could not be listed; folders are its subfolders' names, links to folders among them, and
// files the names of its other entries, shown greyed.
path ui.Field
dir string
folders []string
files []string
// skipped counts the entries whose names the host could not send.
skipped uint32
list ui.ListState
loading bool
// repositories are the folders among folders holding a .git entry, found after the listing
// shows; the list tags them Git.
repositories map[string]bool
list ui.ListState
loading bool
// listing counts the listings, so that only the latest applies.
listing uint64
// readErr is why dir could not be listed; err why the folder could not be opened.
Expand Down Expand Up @@ -175,6 +180,20 @@ func (a *App) leaveRemoteBrowser() {
}
}

// leaveRemoteFlows ends the folder, trust or import page the window shows, so the list beside it
// can show another connection. It reports false, leaving them, while one of them is opening a
// folder or saving an import.
func (a *App) leaveRemoteFlows() bool {
r := &a.remote
if (r.trust != nil && r.trust.deciding) || (r.browser != nil && r.browser.opening) || (r.importer != nil && r.importer.applying) {
return false
}
r.trust = nil
r.importer = nil
a.leaveRemoteBrowser()
return true
}

// backFromRemoteBrowser is Back: the session ends and the form shows again.
func (a *App) backFromRemoteBrowser() {
if a.remote.browser == nil {
Expand Down Expand Up @@ -203,7 +222,7 @@ func (a *App) listRemoteFolder(dir string) {
// log-exempt: 用户取消:已换了文件夹、返回或关闭窗口,不再应用列出结果。
return
}
b.loading, b.folders, b.skipped, b.list = false, nil, 0, ui.ListState{}
b.loading, b.folders, b.files, b.skipped, b.repositories, b.list = false, nil, nil, 0, nil, ui.ListState{}
if err != nil {
a.operationFailed("remote_read_dir", remoteLogError(err))
if remoteConnectionClosed(err) {
Expand All @@ -215,20 +234,69 @@ func (a *App) listRemoteFolder(dir string) {
b.readErr = remoteReadDirFailureText(a.language(), err)
return
}
b.folders, b.skipped = remoteFolders(directory), directory.SkippedNonUTF8
b.folders, b.files, b.skipped = remoteEntryNames(directory, true), remoteEntryNames(directory, false), directory.SkippedNonUTF8
a.markRemoteRepositories(b)
}
})
}

// remoteRepositoryChecks bounds how many of a folder's subfolders are looked into for .git, and
// remoteRepositoryParallel how many of those looks run at once over the session.
const (
remoteRepositoryChecks = 64
remoteRepositoryParallel = 8
)

// markRemoteRepositories looks for a .git entry, a folder or a worktree's file, in the first
// subfolders of the folder b lists, so the list can tag Git repositories once the names show.
// A subfolder whose .git cannot be read stays untagged: the tag is a hint, and the listing
// already reports a lost session.
func (a *App) markRemoteRepositories(b *remoteBrowser) {
names := slices.Clone(b.folders[:min(len(b.folders), remoteRepositoryChecks)])
if len(names) == 0 {
return
}
listing, generation, kernel, session, dir := b.listing, a.remote.generation, a.kernel, b.session.ID, b.dir
a.background(nil, remoteReadDirTimeout, func(ctx context.Context) func(*App) {
found := make([]bool, len(names))
var wait sync.WaitGroup
slots := make(chan struct{}, remoteRepositoryParallel)
for i, name := range names {
wait.Add(1)
slots <- struct{}{}
go func() {
defer func() { <-slots; wait.Done() }()
_, err := kernel.RemoteStat(ctx, session, path.Join(dir, name, ".git"))
found[i] = err == nil
}()
}
wait.Wait()
return func(a *App) {
r := &a.remote
if !r.open || r.generation != generation || r.browser != b || b.listing != listing {
// log-exempt: 用户取消:已换了文件夹、返回或关闭窗口,不再标记 Git 仓库。
return
}
b.repositories = map[string]bool{}
for i, name := range names {
if found[i] {
b.repositories[name] = true
}
}
}
})
}

// remoteFolders are the names of directory's folders and links to folders, hidden ones last.
func remoteFolders(directory core.RemoteDirectory) []string {
var folders []string
// remoteEntryNames are the names of directory's folders and links to folders when folders is
// set, or of its other entries, hidden ones last.
func remoteEntryNames(directory core.RemoteDirectory, folders bool) []string {
var names []string
for _, entry := range directory.Entries {
if entry.Metadata.IsDirectory() {
folders = append(folders, entry.Name)
if entry.Metadata.IsDirectory() == folders {
names = append(names, entry.Name)
}
}
slices.SortStableFunc(folders, func(x, y string) int {
slices.SortStableFunc(names, func(x, y string) int {
hiddenX, hiddenY := strings.HasPrefix(x, "."), strings.HasPrefix(y, ".")
if hiddenX != hiddenY {
if hiddenX {
Expand All @@ -238,7 +306,7 @@ func remoteFolders(directory core.RemoteDirectory) []string {
}
return cmp.Compare(strings.ToLower(x), strings.ToLower(y))
})
return folders
return names
}

// remoteReadDirFailureText says why a host folder could not be listed.
Expand Down
Loading
Loading