Skip to content

Commit f94e037

Browse files
authored
feat: implement file and text search functionality with glob pattern support (#22)
1 parent d93a4e4 commit f94e037

7 files changed

Lines changed: 530 additions & 78 deletions

File tree

com.microsoft.copilot.eclipse.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Require-Bundle: org.eclipse.lsp4e;bundle-version="0.18.1",
4343
org.eclipse.wildwebdeveloper.embedder.node;bundle-version="1.0.3";resolution:=optional,
4444
org.eclipse.core.net;bundle-version="1.5.200",
4545
org.eclipse.core.resources;bundle-version="3.20.0",
46+
org.eclipse.core.filesystem;bundle-version="1.10.200",
4647
org.eclipse.core.runtime;bundle-version="[3.30.0,4.0.0)",
4748
org.apache.httpcomponents.client5.httpclient5;bundle-version="5.2.1",
4849
org.apache.httpcomponents.core5.httpcore5;bundle-version="5.2.3",

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageClient.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
import com.microsoft.copilot.eclipse.core.lsp.protocol.ConversationContextParams;
4848
import com.microsoft.copilot.eclipse.core.lsp.protocol.CurrentEditorContext;
4949
import com.microsoft.copilot.eclipse.core.lsp.protocol.DidChangeFeatureFlagsParams;
50+
import com.microsoft.copilot.eclipse.core.lsp.protocol.FindFilesParams;
51+
import com.microsoft.copilot.eclipse.core.lsp.protocol.FindFilesResult;
52+
import com.microsoft.copilot.eclipse.core.lsp.protocol.FindTextInFilesParams;
53+
import com.microsoft.copilot.eclipse.core.lsp.protocol.FindTextInFilesResult;
5054
import com.microsoft.copilot.eclipse.core.lsp.protocol.GetWatchedFilesRequest;
5155
import com.microsoft.copilot.eclipse.core.lsp.protocol.GetWatchedFilesResponse;
5256
import com.microsoft.copilot.eclipse.core.lsp.protocol.InvokeClientToolConfirmationParams;
@@ -345,6 +349,22 @@ public CompletableFuture<ReadDirectoryResult> readDirectory(String uri) {
345349
return CompletableFuture.supplyAsync(() -> FileUtils.readDirectoryEntries(uri));
346350
}
347351

352+
/**
353+
* Searches for files matching a glob pattern under the given base URI.
354+
*/
355+
@JsonRequest("workspace/findFiles")
356+
public CompletableFuture<FindFilesResult> findFiles(FindFilesParams params) {
357+
return CompletableFuture.supplyAsync(() -> FileUtils.findFiles(params));
358+
}
359+
360+
/**
361+
* Searches for text (or a regex) in files under the given base URI.
362+
*/
363+
@JsonRequest("workspace/findTextInFiles")
364+
public CompletableFuture<FindTextInFilesResult> findTextInFiles(FindTextInFilesParams params) {
365+
return CompletableFuture.supplyAsync(() -> FileUtils.findTextInFiles(params));
366+
}
367+
348368
/**
349369
* Handles the progress notification for chat replies.
350370
*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
package com.microsoft.copilot.eclipse.core.lsp.protocol;
5+
6+
/**
7+
* Parameters for the {@code workspace/findFiles} request. Used by the language server to ask the client to search for
8+
* files matching a glob pattern under a given base URI (e.g. a semanticfs workspace folder).
9+
*
10+
* @param baseUri the base URI to search under (e.g. a semanticfs workspace folder)
11+
* @param pattern the glob pattern to match file paths against
12+
* @param maxResults the maximum number of results to return (optional)
13+
*/
14+
public record FindFilesParams(String baseUri, String pattern, int maxResults) {
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
package com.microsoft.copilot.eclipse.core.lsp.protocol;
5+
6+
import java.util.List;
7+
8+
/**
9+
* Result of the {@code workspace/findFiles} request, containing URIs of files matching the glob pattern.
10+
*
11+
* @param uris the list of file URIs matching the glob pattern
12+
*/
13+
public record FindFilesResult(List<String> uris) {
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
package com.microsoft.copilot.eclipse.core.lsp.protocol;
5+
6+
/**
7+
* Parameters for the {@code workspace/findTextInFiles} request. Used by the language server to ask the client to search
8+
* for text (or a regex) in files under a given base URI.
9+
*
10+
* @param baseUri the base URI to search under (e.g. a semanticfs workspace folder)
11+
* @param query the text or regex pattern to search for in files
12+
* @param isRegexp whether the query is a regular expression
13+
* @param includePattern an optional glob pattern to filter which files to search
14+
* @param maxResults the maximum number of results to return (optional)
15+
*/
16+
public record FindTextInFilesParams(String baseUri, String query, Boolean isRegexp, String includePattern,
17+
int maxResults) {
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
package com.microsoft.copilot.eclipse.core.lsp.protocol;
5+
6+
import java.util.List;
7+
8+
/**
9+
* Result of the {@code workspace/findTextInFiles} request, containing the list of matches.
10+
*
11+
* @param matches the list of text search matches
12+
*/
13+
public record FindTextInFilesResult(List<TextSearchMatch> matches) {
14+
15+
/**
16+
* A single text search match. Field names mirror the CLS protocol.
17+
*
18+
* @param uri the URI of the file containing the match
19+
* @param lineNumber the 1-based line number of the match within the file
20+
* @param lineText the full text of the line containing the match
21+
*/
22+
public record TextSearchMatch(String uri, int lineNumber, String lineText) {
23+
}
24+
25+
}

0 commit comments

Comments
 (0)