Skip to content
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

fix error when get relative path #53

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading