Skip to content

Commit 8b4c296

Browse files
committed
hook up to remote connections, and now secondary sort by match len
1 parent 7e948d8 commit 8b4c296

File tree

4 files changed

+32
-93
lines changed

4 files changed

+32
-93
lines changed

frontend/app/view/preview/preview.tsx

Lines changed: 20 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,90 +1087,29 @@ const SpecializedView = memo(({ parentRef, model }: SpecializedViewProps) => {
10871087
return <SpecializedViewComponent model={model} parentRef={parentRef} />;
10881088
});
10891089

1090-
const mockFileSuggestions: SuggestionType[] = [
1091-
{
1092-
type: "file",
1093-
suggestionid: "1",
1094-
"file:name": "document.txt",
1095-
"file:path": "/home/user/document.txt",
1096-
icon: "file",
1097-
iconcolor: "#4A90E2",
1098-
"file:mimetype": "text/plain",
1099-
},
1100-
{
1101-
type: "file",
1102-
suggestionid: "2",
1103-
"file:name": "presentation.pptx",
1104-
"file:path": "/home/user/presentation.pptx",
1105-
icon: "file-powerpoint",
1106-
iconcolor: "#D04423",
1107-
"file:mimetype": "application/vnd.ms-powerpoint",
1108-
},
1109-
{
1110-
type: "file",
1111-
suggestionid: "3",
1112-
"file:name": "spreadsheet.xlsx",
1113-
"file:path": "/home/user/spreadsheet.xlsx",
1114-
icon: "file-excel",
1115-
iconcolor: "#107C41",
1116-
"file:mimetype": "application/vnd.ms-excel",
1117-
},
1118-
{
1119-
type: "file",
1120-
suggestionid: "4",
1121-
"file:name": "image.png",
1122-
"file:path": "/home/user/image.png",
1123-
icon: "file-image",
1124-
iconcolor: "#E44D26",
1125-
"file:mimetype": "image/png",
1126-
},
1127-
{
1128-
type: "file",
1129-
suggestionid: "5",
1130-
"file:name": "notes.md",
1131-
"file:path": "/home/user/notes.md",
1132-
icon: "file-alt",
1133-
iconcolor: "#777",
1134-
"file:mimetype": "text/markdown",
1135-
},
1136-
];
1137-
11381090
const fetchSuggestions = async (
1139-
cwd: string,
1091+
model: PreviewModel,
11401092
query: string,
11411093
reqContext: SuggestionRequestContext
11421094
): Promise<FetchSuggestionsResponse> => {
1143-
return RpcApi.FetchSuggestionsCommand(TabRpcClient, {
1144-
suggestiontype: "file",
1145-
"file:cwd": cwd,
1146-
query: query,
1147-
widgetid: reqContext.widgetid,
1148-
reqnum: reqContext.reqnum,
1149-
});
1150-
};
1151-
1152-
const mockFetchSuggestions = async (
1153-
query: string,
1154-
reqCtx: SuggestionRequestContext
1155-
): Promise<FetchSuggestionsResponse> => {
1156-
console.log("mock-suggestions", query);
1157-
return new Promise((resolve) => {
1158-
setTimeout(() => {
1159-
if (query == null || !query.trim()) {
1160-
resolve({ suggestions: mockFileSuggestions, reqnum: reqCtx.reqnum });
1161-
} else {
1162-
resolve({
1163-
suggestions: mockFileSuggestions.filter((file) => {
1164-
if (file["file:name"] == null) {
1165-
return false;
1166-
}
1167-
return file["file:name"].toLowerCase().includes(query.toLowerCase());
1168-
}),
1169-
reqnum: reqCtx.reqnum,
1170-
});
1171-
}
1172-
}, 200);
1173-
});
1095+
const fileInfo = await globalStore.get(model.statFile);
1096+
if (fileInfo == null) {
1097+
return null;
1098+
}
1099+
const conn = await globalStore.get(model.connection);
1100+
return await RpcApi.FetchSuggestionsCommand(
1101+
TabRpcClient,
1102+
{
1103+
suggestiontype: "file",
1104+
"file:cwd": fileInfo.dir,
1105+
query: query,
1106+
widgetid: reqContext.widgetid,
1107+
reqnum: reqContext.reqnum,
1108+
},
1109+
{
1110+
route: makeConnRoute(conn),
1111+
}
1112+
);
11741113
};
11751114

11761115
function PreviewView({
@@ -1193,11 +1132,7 @@ function PreviewView({
11931132
model.handleOpenFile(s["file:path"]);
11941133
};
11951134
const fetchSuggestionsFn = async (query, ctx) => {
1196-
const fileInfo = await globalStore.get(model.statFile);
1197-
if (fileInfo == null) {
1198-
return null;
1199-
}
1200-
return await fetchSuggestions(fileInfo.dir, query, ctx);
1135+
return await fetchSuggestions(model, query, ctx);
12011136
};
12021137
return (
12031138
<>

pkg/suggestion/suggestion.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func FetchSuggestions(ctx context.Context, data wshrpc.FetchSuggestionsData) (*w
172172
type scoredEntry struct {
173173
ent fs.DirEntry
174174
score int
175+
fileName string
175176
positions []int
176177
}
177178
var scoredEntries []scoredEntry
@@ -201,20 +202,23 @@ func FetchSuggestions(ctx context.Context, data wshrpc.FetchSuggestionsData) (*w
201202
continue
202203
}
203204
score = result.Score
204-
entry := scoredEntry{ent: de, score: score}
205+
entry := scoredEntry{ent: de, score: score, fileName: fileName}
205206
if positions != nil {
206207
entry.positions = *positions
207208
}
208209
scoredEntries = append(scoredEntries, entry)
209210
} else {
210-
scoredEntries = append(scoredEntries, scoredEntry{ent: de, score: score})
211+
scoredEntries = append(scoredEntries, scoredEntry{ent: de, score: score, fileName: fileName})
211212
}
212213
}
213214

214215
// Sort entries by descending score (better matches first).
215216
if searchTerm != "" {
216217
sort.Slice(scoredEntries, func(i, j int) bool {
217-
return scoredEntries[i].score > scoredEntries[j].score
218+
if scoredEntries[i].score != scoredEntries[j].score {
219+
return scoredEntries[i].score > scoredEntries[j].score
220+
}
221+
return len(scoredEntries[i].fileName) < len(scoredEntries[j].fileName)
218222
})
219223
}
220224

pkg/wshrpc/wshremote/wshremote.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/wavetermdev/waveterm/pkg/remote/connparse"
2121
"github.com/wavetermdev/waveterm/pkg/remote/fileshare/wshfs"
22+
"github.com/wavetermdev/waveterm/pkg/suggestion"
2223
"github.com/wavetermdev/waveterm/pkg/util/fileutil"
2324
"github.com/wavetermdev/waveterm/pkg/util/iochan/iochantypes"
2425
"github.com/wavetermdev/waveterm/pkg/util/tarcopy"
@@ -801,6 +802,10 @@ func (*ServerImpl) RemoteInstallRcFilesCommand(ctx context.Context) error {
801802
return wshutil.InstallRcFiles()
802803
}
803804

805+
func (*ServerImpl) FetchSuggestionsCommand(ctx context.Context, data wshrpc.FetchSuggestionsData) (*wshrpc.FetchSuggestionsResponse, error) {
806+
return suggestion.FetchSuggestions(ctx, data)
807+
}
808+
804809
func logPrintfDev(format string, args ...interface{}) {
805810
if wavebase.IsDevMode() {
806811
log.Printf(format, args...)

pkg/wshrpc/wshserver/wshserver.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/wavetermdev/waveterm/pkg/remote"
2727
"github.com/wavetermdev/waveterm/pkg/remote/conncontroller"
2828
"github.com/wavetermdev/waveterm/pkg/remote/fileshare"
29-
"github.com/wavetermdev/waveterm/pkg/suggestion"
3029
"github.com/wavetermdev/waveterm/pkg/telemetry"
3130
"github.com/wavetermdev/waveterm/pkg/telemetry/telemetrydata"
3231
"github.com/wavetermdev/waveterm/pkg/util/envutil"
@@ -862,7 +861,3 @@ func (ws *WshServer) PathCommand(ctx context.Context, data wshrpc.PathCommandDat
862861
}
863862
return path, nil
864863
}
865-
866-
func (ws *WshServer) FetchSuggestionsCommand(ctx context.Context, data wshrpc.FetchSuggestionsData) (*wshrpc.FetchSuggestionsResponse, error) {
867-
return suggestion.FetchSuggestions(ctx, data)
868-
}

0 commit comments

Comments
 (0)