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
Expand Up @@ -34,6 +34,16 @@ CRLF 行尾的 `\r` 不算行内容。
Core 解析的路径/glob 表达式;没有模块模型时不执行模块查询。包含 Git 忽略文件
是请求选项,不能绕过手动排除和结构隐藏。

交互式项目分页与全局文本搜索使用同一冷查询策略:已有全文索引时复用,否则
直接枚举文件并匹配当前页,不等所有文件建立三元组倒排表后才显示首屏。
旧侧栏在首次查询时强制构建全文索引,导致同一查询比双 Shift 明显更慢;
不要把主动预热或旧同步消费者的索引构建放回交互式分页的必经路径。
文件标题与命中行统一为24pt,文件名只在标题显示一次,命中行缩进并对齐
行列号与正文。两种搜索结果的正文高亮均使用主题的13pt界面字体,避免与文件名
切换字体;编辑器预览仍遵循编辑器自己的字体设置。
全局搜索的类别称为“类型”,包含语言服务报告的类、枚举、接口和结构体,
“符号”保持其他声明;Go 等语言不再被 Java 的“类”文案误导。

宿主在 UI 线程捕获脏文档的不可变 rope 根,在后台生成文本交给 Core。快照加入
候选并替换磁盘文本;后续页复用同一快照,编辑变化取消并重查,查询不写盘。
全局搜索“全部”合并正文来源;名称匹配增加有序片段和低分跳字母匹配,但未完整
Expand All @@ -58,6 +68,8 @@ Core 解析的路径/glob 表达式;没有模块模型时不执行模块查询
- 一直复用现有索引而不接文件监听,会在外部编辑后产生静默漏报,不能采用。
- 每次按键并行启动新查询会积累索引构建任务,浪费资源并可能发布旧结果;采用
输入合并、取消和单查询串行。
- 在冷分页之前强制建立全文索引会读取所有候选两次,增加首屏延迟和常驻倒排表;
使用现成索引或文件清单直接匹配。低命中查询仍需读完可搜索文件,不保证常数时间。
- 项目搜索继续列出文件名匹配、只是排在内容行之后:Core 先收集文件名匹配,文件名
含查询词的文件一多就占满 200 条上限,内容行一条都不剩;IDE 的 Find in Files
也不列文件名,查文件名用全局搜索的“文件”。被否。
Expand All @@ -66,9 +78,23 @@ Core 解析的路径/glob 表达式;没有模块模型时不执行模块查询

结果显示后,收到文件变化事件会自动刷新;通知存在系统固有的投递延迟。
Linux 递归监听需要为目录分别注册,超出上限时会退回手动刷新。
当前分组计数只覆盖已加载行。完整总数、生成目录的临时覆盖、无需先打开文件的
全工作区类/符号索引、符号链接跟随、完整 IDEA 匹配质量与各平台实机验收仍由
[#2199](https://github.com/1lck/Lithe-IDEA/issues/2199) 跟踪;不能把此次改进写成搜索已与 IDEA 对齐。
首屏发布后独立统计全部文件、匹配行和出现次数;只返回当前加载文件的计数明细,
避免把全项目路径传到界面。计数显示进行中/失败与重试,查询、文件和脏文档变化
立即取消旧统计,关闭项目等待统计退出再释放索引。

两个搜索入口提供包含 Git 忽略、插件生成目录和工作区内部符号链接的一次性选项。
手动排除仍优先;外部链接不自动遍历,需要单独打开工作区根。Core 检查规范目标、
祖先循环和目标排除,保留别名路径;替换按规范路径去重。原生目标事件使链接索引
重建,保存使其失效;项目树可展开内部链接,已展开别名在目标事件到达时重新读取。

类型/符号搜索按已启用清单的文件选择器发现项目语言,再启动相关语言服务,不要求
先打开文件。晚到的就绪事件只补问尚未查询的服务,保留其他服务答案;关闭面板、
换查询会取消操作和截止计时器,过期排名结果不能覆盖新结果。语言语义完全来自
标准 workspace/symbol,不维护 Core 语言解析器或第二份符号索引。类型包括 Class、
Enum、Interface、Struct,其余作为符号。界面字体统一为13pt,侧栏24pt行高与图标列对齐。

实现覆盖 #2199 的列举场景,不声称完全等价于 IDEA 所有匹配质量和外部库能力。
两端原生窗口和输入法验收仍须在目标平台完成,不能由无头截图替代。
名称匹配的宽松规则限于 Search Everywhere,通用 `rankNames` 保持原有边界匹配,
避免插件市场等现有候选列表出现额外结果。

Expand All @@ -80,6 +106,7 @@ Linux 递归监听需要为目录分别注册,超出上限时会退回手动
- `scripts/desktop/desktop-go.sh test ./internal/workbench -run TestSearchPanels`:两个搜索界面共享监听并在最后一个消费者关闭时释放。
- `scripts/desktop/desktop-go.sh test ./internal/core -run '^$' -bench '^BenchmarkWorkspaceSearchIndex$' -benchtime=3x`:索引复用与重建开销。
- `scripts/desktop/desktop-go.sh test ./internal/core -run '^$' -bench '^BenchmarkEverywhereSearchIndex$' -benchtime=3x`:全局文件名分页的索引复用与重建开销。
- `scripts/desktop/desktop-go.sh test ./internal/core -run '^$' -bench '^BenchmarkWorkspaceColdContentSearch$' -benchtime=3x`:通过 `LITHE_SEARCH_BENCH_ROOT` 显式选择真实工作区,安装工作台同样的 Git 忽略策略后对比两种冷内容查询。
- `scripts/desktop/desktop-go.sh test ./internal/workbench -run 'TestProjectSearchReadsUnsavedTextAndAllSearchesContents|TestProjectReplacePreservesOriginalEncodingAndRejectsChangedPreview'`:脏文档/All正文及五种编码替换、外部改动保护。
- `scripts/desktop/desktop-go.sh test ./internal/settingswindow ./internal/searchprefs -run 'TestSearchPage|TestSearchPreferences'`:真实来源读写、应用、回读及冲突。
- `scripts/desktop/desktop-go.sh test -tags 'vivahead lithevisual' ./internal/workbench ./internal/settingswindow -run '^TestVisualSearch(Results|Preferences)$'`:明暗主题和中英文截图,需指定 `LITHE_VISUAL_OUTPUT_DIR`。
Expand Down
22 changes: 22 additions & 0 deletions desktop/internal/core/search_languages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package core

import "context"

// SearchLanguageSource contains selectors read from an enabled provider manifest.
type SearchLanguageSource struct {
LanguageID string `json:"languageId"`
FileExtensions []string `json:"fileExtensions,omitempty"`
FileNames []string `json:"fileNames,omitempty"`
}

func (c *Client) SearchWorkspaceLanguages(ctx context.Context, root string, sources []SearchLanguageSource) ([]string, error) {
var result struct {
Languages []string `json:"languages"`
}
err := c.Execute(ctx, "workspace.search", struct {
Root string `json:"root"`
Query string `json:"query"`
LanguageSources []SearchLanguageSource `json:"languageSources"`
}{root, "", nonNil(sources)}, &result)
return result.Languages, err
}
51 changes: 51 additions & 0 deletions desktop/internal/core/search_presentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"github.com/1lck/Lithe-IDEA/desktop/internal/contractfixture"
"os"
"path/filepath"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -42,3 +43,53 @@ func TestSearchPreferencesAndPresentationSharedFixture(t *testing.T) {
t.Fatalf("presentation %+v: %v", got, err)
}
}

func TestSearchCountsAndLanguageDiscoverySharedFixture(t *testing.T) {
data, err := os.ReadFile(contractfixture.CoreFixture("search/idea-search-v1.json"))
if err != nil {
t.Fatal(err)
}
var fixture map[string]json.RawMessage
if err := json.Unmarshal(data, &fixture); err != nil {
t.Fatal(err)
}
for _, name := range []string{"completeCounts", "languageDiscovery"} {
t.Run(name, func(t *testing.T) {
var item struct {
Files map[string]string
Request json.RawMessage
Expected json.RawMessage
}
if err := json.Unmarshal(fixture[name], &item); err != nil {
t.Fatal(err)
}
root := t.TempDir()
for path, text := range item.Files {
file := filepath.Join(root, filepath.FromSlash(path))
if err := os.MkdirAll(filepath.Dir(file), 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(file, []byte(text), 0600); err != nil {
t.Fatal(err)
}
}
var request map[string]any
if err := json.Unmarshal(item.Request, &request); err != nil {
t.Fatal(err)
}
request["root"] = root
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
var got, want any
if err := NewClient().Execute(ctx, "workspace.search", request, &got); err != nil {
t.Fatal(err)
}
if err := json.Unmarshal(item.Expected, &want); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("got %+v, want %+v", got, want)
}
})
}
}
26 changes: 25 additions & 1 deletion desktop/internal/core/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ type WorkspaceNode struct {
// DirectoryListing is the visible children of one directory, directories first and then by
// name, in the kernel's order.
type DirectoryListing struct {
Linked bool `json:"linked"`
// Path is relative to the project root; empty for the root.
Path string `json:"path"`
Children []WorkspaceNode `json:"children"`
Expand Down Expand Up @@ -293,6 +294,7 @@ func (c *Client) ListDirectories(ctx context.Context, root string, paths []strin
var response struct {
Directories []struct {
Path string `json:"path"`
Linked bool `json:"linked"`
Children []rawWorkspaceNode `json:"children"`
} `json:"directories"`
}
Expand All @@ -308,7 +310,7 @@ func (c *Client) ListDirectories(ctx context.Context, root string, paths []strin
Leaf: child.IsDirectory && child.Children != nil && len(*child.Children) == 0,
})
}
listings = append(listings, DirectoryListing{Path: d.Path, Children: children})
listings = append(listings, DirectoryListing{Path: d.Path, Linked: d.Linked, Children: children})
}
return listings, nil
}
Expand All @@ -325,6 +327,10 @@ type WorkspaceSearchRequest struct {
ScopeExpression string `json:"scopeExpression,omitempty"`
ScopePaths []string `json:"scopePaths,omitempty"`
IncludeIgnored bool `json:"includeIgnored,omitempty"`
IncludeGenerated bool `json:"includeGenerated,omitempty"`
FollowSymlinks bool `json:"followSymlinks,omitempty"`
CountPaths []string `json:"countPaths,omitempty"`
CountOnly bool `json:"countOnly,omitempty"`
MaxFileBytes uint64 `json:"maxFileBytes,omitempty"`
TextOverrides map[string]string `json:"textOverrides,omitempty"`
PageSize int `json:"pageSize,omitempty"`
Expand Down Expand Up @@ -363,6 +369,22 @@ type WorkspaceSearchPage struct {
NextCursor *string `json:"nextCursor"`
}

// WorkspaceSearchCounts contains complete totals, independent of the loaded page.
type WorkspaceSearchCounts struct {
Files int `json:"files"`
Lines int `json:"lines"`
Occurrences int `json:"occurrences"`
FileOccurrences map[string]int `json:"fileOccurrences"`
}

func (c *Client) CountWorkspaceSearch(ctx context.Context, request WorkspaceSearchRequest) (WorkspaceSearchCounts, error) {
request.CountOnly = true
request.Cursor = nil
var counts WorkspaceSearchCounts
err := c.Execute(ctx, "workspace.search", request, &counts)
return counts, err
}

type SearchPreferences struct {
MaxFileBytes uint64 `json:"maxFileBytes"`
ReplacementMaxFileBytes uint64 `json:"replacementMaxFileBytes"`
Expand Down Expand Up @@ -409,6 +431,8 @@ type EverywhereSearchRequest struct {
TextOverrides map[string]string `json:"textOverrides,omitempty"`
ScopePaths []string `json:"scopePaths,omitempty"`
IncludeIgnored bool `json:"includeIgnored,omitempty"`
IncludeGenerated bool `json:"includeGenerated,omitempty"`
FollowSymlinks bool `json:"followSymlinks,omitempty"`
}

type EverywhereSearchContext struct {
Expand Down
2 changes: 2 additions & 0 deletions desktop/internal/core/workspace_replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type WorkspaceReplaceRequest struct {
ScopeExpression string `json:"scopeExpression,omitempty"`
ScopePaths []string `json:"scopePaths,omitempty"`
IncludeIgnored bool `json:"includeIgnored,omitempty"`
IncludeGenerated bool `json:"includeGenerated,omitempty"`
FollowSymlinks bool `json:"followSymlinks,omitempty"`
MaxFileBytes uint64 `json:"maxFileBytes,omitempty"`
}

Expand Down
62 changes: 62 additions & 0 deletions desktop/internal/core/workspace_search_latency_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package core

import (
"context"
"os"
"testing"
"time"
)

// BenchmarkWorkspaceColdContentSearch compares the sidebar and popup on the same real checkout.
// An explicit root avoids treating a small generated workspace as a large-project measurement.
func BenchmarkWorkspaceColdContentSearch(b *testing.B) {
root := os.Getenv("LITHE_SEARCH_BENCH_ROOT")
if root == "" {
b.Skip("set LITHE_SEARCH_BENCH_ROOT to a real workspace")
}
query := "LockOSThread"
client := NewClient()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
status, err := client.ConfigureIndexing(ctx, root, "search-latency-benchmark", IndexingPolicyOf(nil, true), false)
cancel()
if err != nil {
b.Fatal(err)
}
b.Cleanup(func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if _, err := client.ReleaseIndexing(ctx, root, "search-latency-benchmark", status.Revision); err != nil {
b.Error(err)
}
})
for _, popup := range []bool{false, true} {
name := "sidebar"
if popup {
name = "popup-text"
}
b.Run(name, func(b *testing.B) {
for b.Loop() {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
if err := client.InvalidateWorkspaceSearch(ctx, root); err != nil {
cancel()
b.Fatal(err)
}
var count int
var err error
if popup {
var page EverywhereSearchPage
page, err = client.SearchEverywherePage(ctx, EverywhereSearchRequest{Root: root, Query: query, PageSize: 50, ResultKinds: []string{"content"}, IncludeContentRanges: true, MaxFileBytes: 16 << 20})
count = len(page.Matches)
} else {
var page WorkspaceSearchPage
page, err = client.SearchWorkspacePage(ctx, WorkspaceSearchRequest{Root: root, Query: query, PageSize: 50, IncludeContentRanges: true, MaxFileBytes: 16 << 20})
count = len(page.Matches)
}
cancel()
if err != nil || count == 0 {
b.Fatalf("real search returned %d matches: %v", count, err)
}
}
})
}
}
Loading
Loading