From d69c6d4f3729374ab40fcebc861e67f2da100ad9 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 4 Oct 2023 10:57:03 -0700 Subject: fix: :bug: fix for windows drive difference bug --- .../continuedev/plugins/context_providers/file.py | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'continuedev/src') diff --git a/continuedev/src/continuedev/plugins/context_providers/file.py b/continuedev/src/continuedev/plugins/context_providers/file.py index f4fbaf03..4cfbcfdb 100644 --- a/continuedev/src/continuedev/plugins/context_providers/file.py +++ b/continuedev/src/continuedev/plugins/context_providers/file.py @@ -1,11 +1,12 @@ import asyncio import os -from typing import List +from typing import List, Optional from ...core.context import ContextProvider from ...core.main import ContextItem, ContextItemDescription, ContextItemId from ...core.sdk import ContinueSDK from ...libs.util.filter_files import DEFAULT_IGNORE_PATTERNS +from ...libs.util.logging import logger from .util import remove_meilisearch_disallowed_chars MAX_SIZE_IN_CHARS = 50_000 @@ -80,14 +81,26 @@ class FileContextProvider(ContextProvider): async def get_context_item_for_filepath( self, absolute_filepath: str - ) -> ContextItem: + ) -> Optional[ContextItem]: content = await get_file_contents(absolute_filepath, self.sdk) if content is None: return None - relative_to_workspace = os.path.relpath( - absolute_filepath, self.sdk.ide.workspace_directory - ) + workspace_dir = self.sdk.ide.workspace_directory + if ( + os.path.splitdrive(workspace_dir)[0] + != os.path.splitdrive(absolute_filepath)[0] + ): + workspace_dir = ( + os.path.splitdrive(absolute_filepath)[0] + + os.path.splitdrive(workspace_dir)[1] + ) + + try: + relative_to_workspace = os.path.relpath(absolute_filepath, workspace_dir) + except Exception as e: + logger.warning(f"Error getting relative path: {e}") + return None return ContextItem( content=content[: min(2000, len(content))], -- cgit v1.2.3-70-g09d2