Skip to content

Commit 7f3deac

Browse files
committed
Add more LSP endpoints and actions representing them.
1 parent 5bb71cf commit 7f3deac

178 files changed

Lines changed: 6819 additions & 690 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

extensions/fine_python_flake8/fine_python_flake8/lint_files_handler.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
from flake8.plugins import finder
1313

1414
from finecode_extension_api import code_action
15-
from fine_lint import lint_files_action
15+
from fine_lint.diagnostic_types import (
16+
Diagnostic,
17+
DiagnosticFilesRunPayload,
18+
DiagnosticFilesRunContext,
19+
DiagnosticFilesRunResult,
20+
DiagnosticSeverity,
21+
Position,
22+
Range,
23+
)
1624
from fine_python_lang.lint_python_files_action import (
1725
LintPythonFilesAction,
1826
)
@@ -25,12 +33,12 @@
2533
from finecode_extension_api.resource_uri import ResourceUri, resource_uri_to_path
2634

2735

28-
def map_flake8_check_result_to_lint_message(result: tuple) -> lint_files_action.LintMessage:
36+
def map_flake8_check_result_to_lint_message(result: tuple) -> Diagnostic:
2937
error_code, line_number, column, text, physical_line = result
30-
return lint_files_action.LintMessage(
31-
range=lint_files_action.Range(
32-
start=lint_files_action.Position(line=line_number - 1, character=column),
33-
end=lint_files_action.Position(
38+
return Diagnostic(
39+
range=Range(
40+
start=Position(line=line_number - 1, character=column),
41+
end=Position(
3442
line=line_number - 1,
3543
character=len(physical_line) if physical_line is not None else column,
3644
),
@@ -39,9 +47,9 @@ def map_flake8_check_result_to_lint_message(result: tuple) -> lint_files_action.
3947
code=error_code,
4048
source="flake8",
4149
severity=(
42-
lint_files_action.LintMessageSeverity.WARNING
50+
DiagnosticSeverity.WARNING
4351
if error_code.startswith("W")
44-
else lint_files_action.LintMessageSeverity.ERROR
52+
else DiagnosticSeverity.ERROR
4553
),
4654
)
4755

@@ -51,8 +59,8 @@ def run_flake8_on_single_file(
5159
file_content: str,
5260
file_ast: ast.Module,
5361
config: Flake8LintFilesHandlerConfig,
54-
) -> list[lint_files_action.LintMessage]:
55-
lint_messages: list[lint_files_action.LintMessage] = []
62+
) -> list[Diagnostic]:
63+
lint_messages: list[Diagnostic] = []
5664
# flake8 expects lines with newline at the end
5765
file_lines = [line + "\n" for line in file_content.split("\n")]
5866
# TODO: investigate whether guide and decider can be reused. They cannot be
@@ -152,15 +160,15 @@ def __init__(
152160

153161
async def run_on_single_file(
154162
self, file_uri: ResourceUri
155-
) -> lint_files_action.LintFilesRunResult | None:
163+
) -> DiagnosticFilesRunResult | None:
156164
file_path = resource_uri_to_path(file_uri)
157-
messages: dict[ResourceUri, list[lint_files_action.LintMessage]] = {}
165+
messages: dict[ResourceUri, list[Diagnostic]] = {}
158166
try:
159167
cached_lint_messages = await self.cache.get_file_cache(
160168
file_path, self.CACHE_KEY
161169
)
162170
messages[file_uri] = cached_lint_messages
163-
return lint_files_action.LintFilesRunResult(messages=messages)
171+
return DiagnosticFilesRunResult(messages=messages)
164172
except icache.CacheMissException:
165173
pass
166174

@@ -188,12 +196,12 @@ async def run_on_single_file(
188196
file_path, file_version, self.CACHE_KEY, lint_messages
189197
)
190198

191-
return lint_files_action.LintFilesRunResult(messages=messages)
199+
return DiagnosticFilesRunResult(messages=messages)
192200

193201
async def run(
194202
self,
195-
payload: lint_files_action.LintFilesRunPayload,
196-
run_context: lint_files_action.LintFilesRunContext,
203+
payload: DiagnosticFilesRunPayload,
204+
run_context: DiagnosticFilesRunContext,
197205
) -> None:
198206
if self.config.select is not None and len(self.config.select) == 0:
199207
# empty set of rules is selected, no need to run flake8
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import atexit
2+
import shutil
3+
import sys
4+
import tempfile
5+
6+
from setuptools import setup
7+
from setuptools.command.build import build
8+
from setuptools.command.build_ext import build_ext
9+
from setuptools.command.build_py import build_py
10+
from setuptools.command.egg_info import egg_info
11+
12+
13+
# Create a single temp directory for all build operations
14+
_TEMP_BUILD_DIR = None
15+
16+
17+
def get_temp_build_dir(pkg_name):
18+
global _TEMP_BUILD_DIR
19+
if _TEMP_BUILD_DIR is None:
20+
_TEMP_BUILD_DIR = tempfile.mkdtemp(prefix=f"{pkg_name}_build_")
21+
atexit.register(lambda: shutil.rmtree(_TEMP_BUILD_DIR, ignore_errors=True))
22+
return _TEMP_BUILD_DIR
23+
24+
25+
class TempDirBuildMixin:
26+
def initialize_options(self):
27+
super().initialize_options()
28+
temp_dir = get_temp_build_dir(self.distribution.get_name())
29+
self.build_base = temp_dir
30+
31+
32+
class TempDirEggInfoMixin:
33+
def initialize_options(self):
34+
super().initialize_options()
35+
temp_dir = get_temp_build_dir(self.distribution.get_name())
36+
self.egg_base = temp_dir
37+
38+
39+
class CustomBuild(TempDirBuildMixin, build):
40+
pass
41+
42+
43+
class CustomBuildPy(TempDirBuildMixin, build_py):
44+
pass
45+
46+
47+
class CustomBuildExt(TempDirBuildMixin, build_ext):
48+
pass
49+
50+
51+
class CustomEggInfo(TempDirEggInfoMixin, egg_info):
52+
def initialize_options(self):
53+
# Don't use temp dir for editable installs
54+
if "--editable" in sys.argv or "-e" in sys.argv:
55+
egg_info.initialize_options(self)
56+
else:
57+
super().initialize_options()
58+
59+
60+
setup(
61+
name="fine_python_import_linter",
62+
cmdclass={
63+
"build": CustomBuild,
64+
"build_py": CustomBuildPy,
65+
"build_ext": CustomBuildExt,
66+
"egg_info": CustomEggInfo,
67+
},
68+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.venvs
2+
*.egg-info/
3+
__pycache__
4+
finecode_config_dump/

extensions/fine_python_lang/fine_python_lang/__init__.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
from fine_python_lang.call_hierarchy_incoming_calls_python_action import (
2+
CallHierarchyIncomingCallsPythonAction,
3+
)
4+
from fine_python_lang.call_hierarchy_outgoing_calls_python_action import (
5+
CallHierarchyOutgoingCallsPythonAction,
6+
)
17
from fine_python_lang.format_python_file_action import FormatPythonFileAction
28
from fine_python_lang.get_lint_fixes_python_files_action import GetLintFixesPythonFilesAction
39
from fine_python_lang.group_src_artifact_files_by_lang_python_handler import (
410
GroupSrcArtifactFilesByLangPythonHandler,
511
)
612
from fine_python_lang.lint_python_files_action import LintPythonFilesAction
13+
from fine_python_lang.type_check_python_files_action import TypeCheckPythonFilesAction
714
from fine_python_lang.list_src_artifact_files_by_lang_python_handler import (
815
ListSrcArtifactFilesByLangPythonHandler,
916
)
@@ -12,18 +19,61 @@
1219
LockPythonDependenciesRunContext,
1320
LockPythonDependenciesRunPayload,
1421
)
22+
from fine_python_lang.text_document_prepare_call_hierarchy_python_action import (
23+
TextDocumentPrepareCallHierarchyPythonAction,
24+
)
25+
from fine_python_lang.text_document_hover_python_action import (
26+
TextDocumentHoverPythonAction,
27+
)
28+
from fine_python_lang.text_document_definition_python_action import (
29+
TextDocumentDefinitionPythonAction,
30+
)
31+
from fine_python_lang.text_document_references_python_action import (
32+
TextDocumentReferencesPythonAction,
33+
)
34+
from fine_python_lang.text_document_type_definition_python_action import (
35+
TextDocumentTypeDefinitionPythonAction,
36+
)
37+
from fine_python_lang.text_document_implementation_python_action import (
38+
TextDocumentImplementationPythonAction,
39+
)
40+
from fine_python_lang.text_document_document_highlight_python_action import (
41+
TextDocumentDocumentHighlightPythonAction,
42+
)
43+
from fine_python_lang.text_document_prepare_type_hierarchy_python_action import (
44+
TextDocumentPrepareTypeHierarchyPythonAction,
45+
)
1546
from fine_python_lang.text_document_semantic_tokens_python_action import (
1647
TextDocumentSemanticTokensPythonAction,
1748
)
49+
from fine_python_lang.type_hierarchy_subtypes_python_action import (
50+
TypeHierarchySubtypesPythonAction,
51+
)
52+
from fine_python_lang.type_hierarchy_supertypes_python_action import (
53+
TypeHierarchySupertypesPythonAction,
54+
)
1855

1956
__all__ = [
57+
"CallHierarchyIncomingCallsPythonAction",
58+
"CallHierarchyOutgoingCallsPythonAction",
2059
"FormatPythonFileAction",
2160
"GetLintFixesPythonFilesAction",
2261
"GroupSrcArtifactFilesByLangPythonHandler",
2362
"LintPythonFilesAction",
63+
"TypeCheckPythonFilesAction",
2464
"ListSrcArtifactFilesByLangPythonHandler",
2565
"LockPythonDependenciesAction",
2666
"LockPythonDependenciesRunContext",
2767
"LockPythonDependenciesRunPayload",
68+
"TextDocumentHoverPythonAction",
69+
"TextDocumentDefinitionPythonAction",
70+
"TextDocumentReferencesPythonAction",
71+
"TextDocumentTypeDefinitionPythonAction",
72+
"TextDocumentImplementationPythonAction",
73+
"TextDocumentDocumentHighlightPythonAction",
74+
"TextDocumentPrepareCallHierarchyPythonAction",
75+
"TextDocumentPrepareTypeHierarchyPythonAction",
2876
"TextDocumentSemanticTokensPythonAction",
77+
"TypeHierarchySubtypesPythonAction",
78+
"TypeHierarchySupertypesPythonAction",
2979
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from finecode_extension_api import code_action
2+
from fine_code_hierarchy.call_hierarchy_incoming_calls_action import (
3+
CallHierarchyIncomingCallsAction,
4+
CallHierarchyIncomingCallsPayload,
5+
CallHierarchyIncomingCallsResult,
6+
)
7+
8+
9+
class CallHierarchyIncomingCallsPythonAction(code_action.Action):
10+
"""Return all incoming calls for a Python call hierarchy item."""
11+
12+
DESCRIPTION = "Return all incoming calls for a Python call hierarchy item."
13+
PAYLOAD_TYPE = CallHierarchyIncomingCallsPayload
14+
RESULT_TYPE = CallHierarchyIncomingCallsResult
15+
LANGUAGE = "python"
16+
PARENT_ACTION = CallHierarchyIncomingCallsAction
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from finecode_extension_api import code_action
2+
from fine_code_hierarchy.call_hierarchy_outgoing_calls_action import (
3+
CallHierarchyOutgoingCallsAction,
4+
CallHierarchyOutgoingCallsPayload,
5+
CallHierarchyOutgoingCallsResult,
6+
)
7+
8+
9+
class CallHierarchyOutgoingCallsPythonAction(code_action.Action):
10+
"""Return all outgoing calls from a Python call hierarchy item."""
11+
12+
DESCRIPTION = "Return all outgoing calls from a Python call hierarchy item."
13+
PAYLOAD_TYPE = CallHierarchyOutgoingCallsPayload
14+
RESULT_TYPE = CallHierarchyOutgoingCallsResult
15+
LANGUAGE = "python"
16+
PARENT_ACTION = CallHierarchyOutgoingCallsAction
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
from finecode_extension_api import code_action
2-
from fine_lint.lint_files_action import (
3-
LintFilesAction,
4-
LintFilesRunContext,
5-
LintFilesRunPayload,
6-
LintFilesRunResult,
2+
from fine_lint.diagnostic_types import (
3+
DiagnosticFilesRunPayload,
4+
DiagnosticFilesRunContext,
5+
DiagnosticFilesRunResult,
76
)
7+
from fine_lint.lint_files_action import LintFilesAction
88

99

1010
class LintPythonFilesAction(
1111
code_action.Action[
12-
LintFilesRunPayload,
13-
LintFilesRunContext,
14-
LintFilesRunResult,
12+
DiagnosticFilesRunPayload,
13+
DiagnosticFilesRunContext,
14+
DiagnosticFilesRunResult,
1515
]
1616
):
1717
"""Lint Python source files and report diagnostics."""
1818

1919
DESCRIPTION = "Lint Python source files and report diagnostics."
20-
PAYLOAD_TYPE = LintFilesRunPayload
21-
RUN_CONTEXT_TYPE = LintFilesRunContext
22-
RESULT_TYPE = LintFilesRunResult
20+
PAYLOAD_TYPE = DiagnosticFilesRunPayload
21+
RUN_CONTEXT_TYPE = DiagnosticFilesRunContext
22+
RESULT_TYPE = DiagnosticFilesRunResult
2323
LANGUAGE = "python"
2424
PARENT_ACTION = LintFilesAction
2525
HANDLER_EXECUTION = code_action.HandlerExecution.CONCURRENT
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from finecode_extension_api import code_action
2+
from fine_symbol_info.text_document_definition_action import (
3+
DefinitionPayload,
4+
DefinitionResult,
5+
TextDocumentDefinitionAction,
6+
)
7+
8+
9+
class TextDocumentDefinitionPythonAction(code_action.Action):
10+
"""Find the definition location(s) of the symbol at a Python document position."""
11+
12+
DESCRIPTION = "Find the definition location(s) of the symbol at a Python document position."
13+
PAYLOAD_TYPE = DefinitionPayload
14+
RESULT_TYPE = DefinitionResult
15+
LANGUAGE = "python"
16+
PARENT_ACTION = TextDocumentDefinitionAction
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from finecode_extension_api import code_action
2+
from fine_symbol_info.text_document_document_highlight_action import (
3+
DocumentHighlightPayload,
4+
DocumentHighlightResult,
5+
TextDocumentDocumentHighlightAction,
6+
)
7+
8+
9+
class TextDocumentDocumentHighlightPythonAction(code_action.Action):
10+
"""Find all document highlight ranges for the symbol at a Python document position."""
11+
12+
DESCRIPTION = "Find all document highlight ranges for the symbol at a Python document position."
13+
PAYLOAD_TYPE = DocumentHighlightPayload
14+
RESULT_TYPE = DocumentHighlightResult
15+
LANGUAGE = "python"
16+
PARENT_ACTION = TextDocumentDocumentHighlightAction
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from finecode_extension_api import code_action
2+
from fine_symbol_info.text_document_hover_action import (
3+
HoverPayload,
4+
HoverResult,
5+
TextDocumentHoverAction,
6+
)
7+
8+
9+
class TextDocumentHoverPythonAction(code_action.Action):
10+
"""Return hover documentation for the symbol at a Python document position."""
11+
12+
DESCRIPTION = "Return hover documentation for the symbol at a Python document position."
13+
PAYLOAD_TYPE = HoverPayload
14+
RESULT_TYPE = HoverResult
15+
LANGUAGE = "python"
16+
PARENT_ACTION = TextDocumentHoverAction

0 commit comments

Comments
 (0)