From 1031f9814666478a883421ba1e2fde7376b38b3a Mon Sep 17 00:00:00 2001
From: xiangtianyu <tjjxiang@gmail.com>
Date: Wed, 17 Jul 2024 17:46:53 +0800
Subject: [PATCH] fix error when get relative path

---
 .../llms/aigateway/AIGatewayServiceProvider.java             | 5 +++--
 .../integrations/llms/trial/TrialServiceProvider.java        | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/zhongan/devpilot/integrations/llms/aigateway/AIGatewayServiceProvider.java b/src/main/java/com/zhongan/devpilot/integrations/llms/aigateway/AIGatewayServiceProvider.java
index 279b2fee..91024278 100644
--- a/src/main/java/com/zhongan/devpilot/integrations/llms/aigateway/AIGatewayServiceProvider.java
+++ b/src/main/java/com/zhongan/devpilot/integrations/llms/aigateway/AIGatewayServiceProvider.java
@@ -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();
 
diff --git a/src/main/java/com/zhongan/devpilot/integrations/llms/trial/TrialServiceProvider.java b/src/main/java/com/zhongan/devpilot/integrations/llms/trial/TrialServiceProvider.java
index 71a996b9..72327f43 100644
--- a/src/main/java/com/zhongan/devpilot/integrations/llms/trial/TrialServiceProvider.java
+++ b/src/main/java/com/zhongan/devpilot/integrations/llms/trial/TrialServiceProvider.java
@@ -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();