-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eclipse): support to collect additional context used for code co…
…mpletion. (#2971) * feat(eclipse): impl git provider lsp client. * feat(eclipse): add client side language support based on lsp4e. * chore(eclipse): bump build number.
- Loading branch information
Showing
13 changed files
with
371 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 73 additions & 1 deletion
74
clients/eclipse/plugin/src/com/tabbyml/tabby4eclipse/lsp/LanguageClientImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,92 @@ | ||
package com.tabbyml.tabby4eclipse.lsp; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.lsp4j.LocationLink; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4j.SemanticTokensRangeParams; | ||
import org.eclipse.jface.text.IDocument; | ||
import org.eclipse.lsp4e.LSPEclipseUtils; | ||
import org.eclipse.lsp4e.LanguageServers; | ||
import org.eclipse.lsp4j.DeclarationParams; | ||
import org.eclipse.lsp4j.Location; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Either; | ||
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification; | ||
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest; | ||
|
||
import com.tabbyml.tabby4eclipse.git.GitProvider; | ||
import com.tabbyml.tabby4eclipse.lsp.protocol.Config; | ||
import com.tabbyml.tabby4eclipse.lsp.protocol.GitDiffParams; | ||
import com.tabbyml.tabby4eclipse.lsp.protocol.GitDiffResult; | ||
import com.tabbyml.tabby4eclipse.lsp.protocol.GitRepository; | ||
import com.tabbyml.tabby4eclipse.lsp.protocol.GitRepositoryParams; | ||
import com.tabbyml.tabby4eclipse.lsp.protocol.ReadFileParams; | ||
import com.tabbyml.tabby4eclipse.lsp.protocol.ReadFileResult; | ||
import com.tabbyml.tabby4eclipse.lsp.protocol.SemanticTokensRangeResult; | ||
import com.tabbyml.tabby4eclipse.lsp.protocol.StatusInfo; | ||
|
||
public class LanguageClientImpl extends org.eclipse.lsp4e.LanguageClientImpl { | ||
@JsonNotification("tabby/status/didChange") | ||
void statusDidChange(StatusInfo params) { | ||
StatusInfoHolder.getInstance().setStatusInfo(params); | ||
} | ||
|
||
@JsonNotification("tabby/config/didChange") | ||
void statusDidChange(Config params) { | ||
ServerConfigHolder.getInstance().setConfig(params); | ||
} | ||
|
||
@JsonRequest("tabby/workspaceFileSystem/readFile") | ||
CompletableFuture<ReadFileResult> workspaceReadFile(ReadFileParams params) { | ||
if (params.getFormat().equals("text")) { | ||
try { | ||
URI uri = new URI(params.getUri()); | ||
IDocument document = LSPEclipseUtils.getDocument(uri); | ||
Range range = params.getRange(); | ||
|
||
ReadFileResult result = new ReadFileResult(); | ||
if (range != null) { | ||
int start = LSPEclipseUtils.toOffset(range.getStart(), document); | ||
int end = LSPEclipseUtils.toOffset(range.getEnd(), document); | ||
result.setText(document.get(start, end - start)); | ||
} else { | ||
result.setText(document.get()); | ||
} | ||
return CompletableFuture.completedFuture(result); | ||
} catch (Exception e) { | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
} else { | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
} | ||
|
||
@JsonRequest("tabby/git/repository") | ||
CompletableFuture<GitRepository> gitRepository(GitRepositoryParams params) { | ||
CompletableFuture<GitRepository> future = new CompletableFuture<>(); | ||
GitRepository result = GitProvider.getInstance().getRepository(params); | ||
future.complete(result); | ||
return future; | ||
} | ||
|
||
@JsonRequest("tabby/git/diff") | ||
CompletableFuture<GitDiffResult> gitDiff(GitDiffParams params) { | ||
CompletableFuture<GitDiffResult> future = new CompletableFuture<>(); | ||
GitDiffResult result = GitProvider.getInstance().getDiff(params); | ||
future.complete(result); | ||
return future; | ||
} | ||
|
||
@JsonRequest("tabby/languageSupport/textDocument/declaration") | ||
CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> languageSupportDeclaration( | ||
DeclarationParams params) { | ||
return LanguageSupportProvider.getInstance().languageSupportDeclaration(params); | ||
} | ||
|
||
@JsonRequest("tabby/languageSupport/textDocument/semanticTokens/range") | ||
CompletableFuture<SemanticTokensRangeResult> languageSupportSemanticTokensRange(SemanticTokensRangeParams params) { | ||
return LanguageSupportProvider.getInstance().languageSupportSemanticTokensRange(params); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
clients/eclipse/plugin/src/com/tabbyml/tabby4eclipse/lsp/LanguageSupportProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.tabbyml.tabby4eclipse.lsp; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.net.URI; | ||
|
||
import org.eclipse.jface.text.IDocument; | ||
import org.eclipse.lsp4e.LSPEclipseUtils; | ||
import org.eclipse.lsp4e.LanguageServers; | ||
import org.eclipse.lsp4j.DeclarationParams; | ||
import org.eclipse.lsp4j.Location; | ||
import org.eclipse.lsp4j.LocationLink; | ||
import org.eclipse.lsp4j.SemanticTokensLegend; | ||
import org.eclipse.lsp4j.SemanticTokensRangeParams; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Either; | ||
|
||
import com.tabbyml.tabby4eclipse.Logger; | ||
import com.tabbyml.tabby4eclipse.lsp.protocol.SemanticTokensRangeResult; | ||
|
||
public class LanguageSupportProvider { | ||
public static LanguageSupportProvider getInstance() { | ||
return LazyHolder.INSTANCE; | ||
} | ||
|
||
private static class LazyHolder { | ||
private static final LanguageSupportProvider INSTANCE = new LanguageSupportProvider(); | ||
} | ||
|
||
private Logger logger = new Logger("LanguageSupportProvider"); | ||
|
||
CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> languageSupportDeclaration( | ||
DeclarationParams params) { | ||
try { | ||
URI uri = new URI(params.getTextDocument().getUri()); | ||
IDocument document = LSPEclipseUtils.getDocument(uri); | ||
|
||
CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> future = LanguageServers | ||
.forDocument(document).withFilter((serverCapabilities) -> { | ||
return serverCapabilities.getDeclarationProvider() != null; | ||
}).computeFirst((wrapper, server) -> { | ||
return server.getTextDocumentService().declaration(params); | ||
}).thenApply((result) -> { | ||
if (result.isPresent()) { | ||
return result.get(); | ||
} else { | ||
return null; | ||
} | ||
}); | ||
return future; | ||
} catch (Exception e) { | ||
logger.error("Error while processing languageSupport/declaration.", e); | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
} | ||
|
||
CompletableFuture<SemanticTokensRangeResult> languageSupportSemanticTokensRange(SemanticTokensRangeParams params) { | ||
try { | ||
URI uri = new URI(params.getTextDocument().getUri()); | ||
IDocument document = LSPEclipseUtils.getDocument(uri); | ||
|
||
CompletableFuture<SemanticTokensRangeResult> future = LanguageServers.forDocument(document) | ||
.withFilter((serverCapabilities) -> { | ||
return serverCapabilities.getSelectionRangeProvider() != null; | ||
}).computeFirst((wrapper, server) -> { | ||
return server.getTextDocumentService().semanticTokensRange(params).thenApply((tokens) -> { | ||
SemanticTokensRangeResult result = new SemanticTokensRangeResult(); | ||
SemanticTokensLegend legend = wrapper.getServerCapabilities().getSemanticTokensProvider() | ||
.getLegend(); | ||
result.setLegend(legend); | ||
result.setTokens(tokens); | ||
return result; | ||
}); | ||
}).thenApply((result) -> { | ||
if (result.isPresent()) { | ||
return result.get(); | ||
} else { | ||
return null; | ||
} | ||
}); | ||
return future; | ||
} catch (Exception e) { | ||
logger.error("Error while processing languageSupport/semanticTokens/range.", e); | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
clients/eclipse/plugin/src/com/tabbyml/tabby4eclipse/lsp/protocol/GitDiffParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.tabbyml.tabby4eclipse.lsp.protocol; | ||
|
||
public class GitDiffParams { | ||
private String repository; | ||
private boolean cached; | ||
|
||
public GitDiffParams() { | ||
} | ||
|
||
public GitDiffParams(String repository) { | ||
this.repository = repository; | ||
this.cached = false; | ||
} | ||
|
||
public GitDiffParams(String repository, boolean cached) { | ||
this.repository = repository; | ||
this.cached = cached; | ||
} | ||
|
||
public String getRepository() { | ||
return repository; | ||
} | ||
|
||
public void setRepository(String repository) { | ||
this.repository = repository; | ||
} | ||
|
||
public boolean getCached() { | ||
return cached; | ||
} | ||
|
||
public void setCached(boolean cached) { | ||
this.cached = cached; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
clients/eclipse/plugin/src/com/tabbyml/tabby4eclipse/lsp/protocol/GitDiffResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.tabbyml.tabby4eclipse.lsp.protocol; | ||
|
||
public class GitDiffResult { | ||
private String diff; | ||
|
||
public GitDiffResult() { | ||
} | ||
|
||
public GitDiffResult(String diff) { | ||
this.diff = diff; | ||
} | ||
|
||
public String getDiff() { | ||
return diff; | ||
} | ||
|
||
public void setDiff(String diff) { | ||
this.diff = diff; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
clients/eclipse/plugin/src/com/tabbyml/tabby4eclipse/lsp/protocol/GitRepositoryParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.tabbyml.tabby4eclipse.lsp.protocol; | ||
|
||
public class GitRepositoryParams { | ||
private String uri; | ||
|
||
public GitRepositoryParams(String uri) { | ||
this.uri = uri; | ||
} | ||
|
||
public String getUri() { | ||
return uri; | ||
} | ||
|
||
public void setUri(String uri) { | ||
this.uri = uri; | ||
} | ||
} |
Oops, something went wrong.