Skip to content

Commit

Permalink
Merge pull request openpilot-hub#53 from xiangtianyu/fix-read-action-…
Browse files Browse the repository at this point in the history
…error

fix error when get relative path
  • Loading branch information
myoss authored Jul 18, 2024
2 parents 33f8140 + 1031f98 commit b794f4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,22 @@ public DevPilotMessage instructCompletion(DevPilotInstructCompletionRequest inst
final Document[] document = new Document[1];
final Language[] language = new Language[1];
final VirtualFile[] virtualFile = new VirtualFile[1];
final String[] relativePath = new String[1];

ApplicationManager.getApplication().runReadAction(() -> {
document[0] = editor.getDocument();
language[0] = PsiDocumentManager.getInstance(editor.getProject()).getPsiFile(document[0]).getLanguage();
virtualFile[0] = FileDocumentManager.getInstance().getFile(document[0]);
relativePath[0] = getRelativeFilePath(editor.getProject(), virtualFile[0]);
});

String text = document[0].getText();
String relativePath = getRelativeFilePath(editor.getProject(), virtualFile[0]);

Map<String, String> map = new HashMap<>();
map.put("document", text);
map.put("position", String.valueOf(offset));
map.put("language", language[0].getID());
map.put("filePath", relativePath);
map.put("filePath", relativePath[0]);
map.put("completionType", instructCompletionRequest.getCompletionType());
ObjectMapper objectMapper = new ObjectMapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,22 @@ public DevPilotMessage instructCompletion(DevPilotInstructCompletionRequest inst
final Document[] document = new Document[1];
final Language[] language = new Language[1];
final VirtualFile[] virtualFile = new VirtualFile[1];
final String[] relativePath = new String[1];

ApplicationManager.getApplication().runReadAction(() -> {
document[0] = editor.getDocument();
language[0] = PsiDocumentManager.getInstance(editor.getProject()).getPsiFile(document[0]).getLanguage();
virtualFile[0] = FileDocumentManager.getInstance().getFile(document[0]);
relativePath[0] = getRelativeFilePath(editor.getProject(), virtualFile[0]);
});

String text = document[0].getText();
String relativePath = getRelativeFilePath(editor.getProject(), virtualFile[0]);

Map<String, String> map = new HashMap<>();
map.put("document", text);
map.put("position", String.valueOf(offset));
map.put("language", language[0].getID());
map.put("filePath", relativePath);
map.put("filePath", relativePath[0]);
map.put("completionType", instructCompletionRequest.getCompletionType());
ObjectMapper objectMapper = new ObjectMapper();

Expand Down

0 comments on commit b794f4b

Please sign in to comment.