-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show version in UI of IntelliJ plugin #2998
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
495695b
create branch
Hossain2024 a9c1dd9
created requestbuilder to pass the methodname . extracted the respons…
Hossain2024 a1db883
created requestbuilder to pass the methodname . extracted the respons…
Hossain2024 911ee78
created requestbuilder to pass the methodname . extracted the respons…
Hossain2024 7052386
removed empty spaces
Hossain2024 081521e
the updated code starts the server with kiota rpc command and calls t…
Hossain2024 d421608
the updated code starts the server with kiota rpc command and calls t…
Hossain2024 dfa241a
Cleaned up code. Changed method header for createRequest method to be…
Hossain2024 829977c
Cleaned up code. Changed method header for createRequest method to be…
Hossain2024 0eba287
Apply suggestions from code review
baywet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package services; | ||
import com.github.arteam.simplejsonrpc.client.JsonRpcClient; | ||
import com.github.arteam.simplejsonrpc.client.builder.RequestBuilder; | ||
public class KiotaJavaClient{ | ||
private final JsonRpcClient client; | ||
public KiotaJavaClient() { | ||
client = new JsonRpcClient(new ProcessTransport("kiota", "rpc")); | ||
} | ||
public <T> RequestBuilder<T> createRequest(String method, Class<T> returnType) { | ||
return client.createRequest() | ||
.method(method) | ||
.returnAs(returnType); | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
intellij/src/main/java/services/MyKiotaProjectService.java
This file was deleted.
Oops, something went wrong.
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,89 @@ | ||
package services; | ||
import com.github.arteam.simplejsonrpc.client.Transport; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
public class ProcessTransport implements Transport { | ||
private final String[] processCommandsAndArgs; | ||
public ProcessTransport(String... processCommandsAndArgs) { | ||
if (processCommandsAndArgs.length == 0) { | ||
throw new IllegalArgumentException("processCommandsAndArgs must not be empty"); | ||
} | ||
this.processCommandsAndArgs = processCommandsAndArgs; | ||
} | ||
@Override | ||
public String pass(String request) throws IOException { | ||
final ProcessBuilder builder = new ProcessBuilder(processCommandsAndArgs); | ||
final Process process = builder.start(); | ||
process.onExit().thenAccept((exitCode) -> { | ||
System.out.println("Process exited with code: " + exitCode); | ||
}); | ||
final BufferedReader stdout = process.inputReader(StandardCharsets.UTF_8); | ||
final OutputStream stdin = process.getOutputStream(); | ||
String idToInsert = "\"id\":1,"; | ||
String payload = "Content-Length: " + (request.length() + idToInsert.length()) + "\r\n" + | ||
"\r\n" + | ||
new StringBuilder(request).insert(1, idToInsert).toString(); | ||
stdin.write(payload.getBytes(StandardCharsets.UTF_8)); | ||
stdin.flush(); | ||
|
||
|
||
final Map<String, String> headers = readResponseHeaders(stdout); | ||
final int contentLength = Integer.parseInt(headers.get("Content-Length")); | ||
StringBuilder responseBuilder = new StringBuilder(); | ||
int character; | ||
for(int i = 0; i < contentLength; i++) { | ||
character = stdout.read(); | ||
char c = (char) character; | ||
responseBuilder.append(c); | ||
} | ||
final String response = responseBuilder.toString(); | ||
stdout.close(); | ||
stdin.close(); | ||
try { | ||
process.waitFor(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should consider using the logger here too. |
||
} | ||
process.destroyForcibly(); | ||
return response; | ||
} | ||
private Map<String, String> readResponseHeaders(BufferedReader stdOut) throws IOException { | ||
StringBuilder headerKey = new StringBuilder(); | ||
StringBuilder headerValue = new StringBuilder(); | ||
boolean readingKey = true; | ||
final HashMap<String, String> headers = new HashMap<>(); | ||
int character; | ||
int nCount = 0; | ||
while ((character = stdOut.read()) != -1) { | ||
char c = (char) character; | ||
if (c == '\r') { | ||
continue; | ||
} else if (c == '\n') { | ||
if (!readingKey) { | ||
readingKey = true; | ||
headers.put(headerKey.toString(), headerValue.toString()); | ||
} | ||
nCount++; | ||
if (nCount == 2) { | ||
break; | ||
} | ||
} else if (c == ':' && readingKey) { | ||
readingKey = false; | ||
stdOut.read(); // Consume the space after the colon | ||
continue; | ||
} else { | ||
nCount = 0; | ||
} | ||
if (readingKey) { | ||
headerKey.append(c); | ||
} else { | ||
headerValue.append(c); | ||
} | ||
} | ||
return headers; | ||
} | ||
} |
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,13 @@ | ||
package services; | ||
|
||
import com.github.arteam.simplejsonrpc.client.builder.RequestBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
public class VersionHandler { | ||
final KiotaJavaClient client = new KiotaJavaClient(); | ||
|
||
public String getVersion() throws IOException { | ||
return client.createRequest("GetVersion", String.class).execute(); | ||
} | ||
} |
20 changes: 10 additions & 10 deletions
20
...n/java/toolWindow/MyKiotaToolFactory.java → ...ain/java/toolWindow/KiotaToolFactory.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
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
13 changes: 0 additions & 13 deletions
13
intellij/src/test/kotlin/com/github/hossain2024/intellijtestplugin/MyPluginTest.kt
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,39 +1,26 @@ | ||
package com.github.hossain2024.intellijtestplugin | ||
|
||
import com.intellij.ide.highlighter.XmlFileType | ||
import com.intellij.openapi.components.service | ||
import com.intellij.psi.xml.XmlFile | ||
import com.intellij.testFramework.TestDataPath | ||
import com.intellij.testFramework.fixtures.BasePlatformTestCase | ||
import com.intellij.util.PsiErrorElementUtil | ||
import com.github.hossain2024.intellijtestplugin.services.MyProjectService | ||
|
||
@TestDataPath("\$CONTENT_ROOT/src/test/testData") | ||
class MyPluginTest : BasePlatformTestCase() { | ||
|
||
fun testXMLFile() { | ||
val psiFile = myFixture.configureByText(XmlFileType.INSTANCE, "<foo>bar</foo>") | ||
val xmlFile = assertInstanceOf(psiFile, XmlFile::class.java) | ||
|
||
assertFalse(PsiErrorElementUtil.hasErrors(project, xmlFile.virtualFile)) | ||
|
||
assertNotNull(xmlFile.rootTag) | ||
|
||
xmlFile.rootTag?.let { | ||
assertEquals("foo", it.name) | ||
assertEquals("bar", it.value.text) | ||
} | ||
} | ||
|
||
fun testRename() { | ||
myFixture.testRename("foo.xml", "foo_after.xml", "a2") | ||
} | ||
|
||
fun testProjectService() { | ||
val projectService = project.service<MyProjectService>() | ||
|
||
assertNotSame(projectService.getRandomNumber(), projectService.getRandomNumber()) | ||
} | ||
|
||
override fun getTestDataPath() = "src/test/testData/rename" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using com.intellij.openapi.diagnostic.Logger instead of System.out.println. This is just a note for the future and not this PR.