99import fine_python_mypy .output_parser as output_parser
1010
1111from finecode_extension_api import code_action
12- from finecode_extension_api .actions .code_quality import lint_action
12+ from finecode_extension_api .actions .code_quality import lint_files_action
13+ from finecode_extension_api .actions .code_quality .lint_python_files_action import (
14+ LintPythonFilesAction ,
15+ )
1316from finecode_extension_api .interfaces import (
1417 icache ,
1518 icommandrunner ,
1821 iextensionrunnerinfoprovider ,
1922 iprojectinfoprovider ,
2023)
24+ from finecode_extension_api .resource_uri import path_to_resource_uri , resource_uri_to_path
2125
2226
2327class DmypyFailedError (Exception ): ...
2428
2529
2630@dataclasses .dataclass
27- class MypyManyCodeActionConfig (code_action .ActionHandlerConfig ): ...
31+ class MypyLintFilesHandlerConfig (code_action .ActionHandlerConfig ): ...
2832
2933
30- class MypyLintHandler (
31- code_action .ActionHandler [lint_action . LintAction , MypyManyCodeActionConfig ]
34+ class MypyLintFilesHandler (
35+ code_action .ActionHandler [LintPythonFilesAction , MypyLintFilesHandlerConfig ]
3236):
3337 CACHE_KEY = "mypy"
34- FILE_OPERATION_AUTHOR = ifileeditor .FileOperationAuthor (erovid )
38+ FILE_OPERATION_AUTHOR = ifileeditor .FileOperationAuthor ('Mypy' )
3539
3640 DMYPY_ARGS = [
3741 "--no-color-output" ,
@@ -72,22 +76,23 @@ def __init__(
7276
7377 async def run_on_single_file (
7478 self ,
79+ file_uri : str ,
7580 file_path : Path ,
7681 project_path : Path ,
7782 all_project_files : list [Path ],
7883 action_run_id : int ,
79- ) -> lint_action . LintRunResult :
84+ ) -> lint_files_action . LintFilesRunResult :
8085 # if mypy was run on the file, the result will be found in cache. If result
8186 # is not in cache, we need additionally to check whether mypy is not running
8287 # on the file right now, because we run mypy on the whole packages.
83- messages : dict [str , list [lint_action .LintMessage ]] = {}
88+ messages : dict [str , list [lint_files_action .LintMessage ]] = {}
8489 # TODO: right cache with dependencies
8590 try :
8691 cached_lint_messages = await self .cache .get_file_cache (
8792 file_path , self .CACHE_KEY
8893 )
89- messages [str ( file_path ) ] = cached_lint_messages
90- return lint_action . LintRunResult (messages = messages )
94+ messages [file_uri ] = cached_lint_messages
95+ return lint_files_action . LintFilesRunResult (messages = messages )
9196 except icache .CacheMissException :
9297 pass
9398
@@ -105,8 +110,8 @@ async def run_on_single_file(
105110 # if checking failed, there are no results in cache
106111 cached_lint_messages = []
107112
108- messages [str ( file_path ) ] = cached_lint_messages
109- return lint_action . LintRunResult (messages = messages )
113+ messages [file_uri ] = cached_lint_messages
114+ return lint_files_action . LintFilesRunResult (messages = messages )
110115 else :
111116 # save file versions at the beginning because file can be changed during
112117 # checking and we want to cache result for current version, not for changed
@@ -129,7 +134,7 @@ async def run_on_single_file(
129134 project_path , all_project_files
130135 )
131136 messages = {
132- str (file_path ): lint_messages
137+ path_to_resource_uri (file_path ): lint_messages
133138 for (
134139 file_path ,
135140 lint_messages ,
@@ -159,12 +164,12 @@ async def run_on_single_file(
159164 project_checked_event .set ()
160165 del self ._projects_being_checked_done_events [project_path ]
161166
162- return lint_action . LintRunResult (messages = messages )
167+ return lint_files_action . LintFilesRunResult (messages = messages )
163168
164169 async def _run_dmypy_on_project (
165170 self , project_dir_path : Path , all_project_files : list [Path ]
166- ) -> dict [Path , list [lint_action .LintMessage ]]:
167- new_messages : dict [str , list [lint_action .LintMessage ]] = {}
171+ ) -> dict [Path , list [lint_files_action .LintMessage ]]:
172+ new_messages : dict [str , list [lint_files_action .LintMessage ]] = {}
168173 if project_dir_path not in self ._process_lock_by_cwd :
169174 self ._process_lock_by_cwd [project_dir_path ] = asyncio .Lock ()
170175
@@ -181,7 +186,9 @@ async def _run_dmypy_on_project(
181186 content = dmypy_run_output , severity = {}
182187 )
183188 new_messages .update (project_lint_messages )
184- all_processed_files_with_messages : dict [Path , list [lint_action .LintMessage ]] = {
189+ all_processed_files_with_messages : dict [
190+ Path , list [lint_files_action .LintMessage ]
191+ ] = {
185192 file_path : [] for file_path in all_project_files
186193 }
187194 all_processed_files_with_messages .update (
@@ -194,20 +201,27 @@ async def _run_dmypy_on_project(
194201
195202 async def run (
196203 self ,
197- payload : lint_action . LintRunPayload ,
198- run_context : lint_action . LintRunContext ,
204+ payload : lint_files_action . LintFilesRunPayload ,
205+ run_context : lint_files_action . LintFilesRunContext ,
199206 ) -> None :
200- file_paths = [file_path async for file_path in payload ]
207+ file_uris = [file_uri async for file_uri in payload ]
208+ file_paths = [resource_uri_to_path (file_uri ) for file_uri in file_uris ]
209+ file_uri_by_path = {
210+ file_path : file_uri
211+ for file_path , file_uri in zip (file_paths , file_uris , strict = False )
212+ }
201213
202214 files_by_projects : dict [Path , list [Path ]] = self .group_files_by_projects (
203215 file_paths , self .project_info_provider .get_current_project_dir_path ()
204216 )
205217
206218 for project_path , project_files in files_by_projects .items ():
207219 for file_path in project_files :
220+ file_uri = file_uri_by_path .get (file_path , path_to_resource_uri (file_path ))
208221 run_context .partial_result_scheduler .schedule (
209- file_path ,
222+ file_uri ,
210223 self .run_on_single_file (
224+ file_uri ,
211225 file_path ,
212226 project_path ,
213227 project_files ,
0 commit comments