siada-cli 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. agent_config.yaml +34 -0
  2. siada/__init__.py +13 -0
  3. siada/agent_hub/__init__.py +10 -0
  4. siada/agent_hub/coder/bug_fix_agent.py +398 -0
  5. siada/agent_hub/coder/code_gen_agent.py +235 -0
  6. siada/agent_hub/coder/fe_gen_agent.py +37 -0
  7. siada/agent_hub/coder/issue_review_agent.py +68 -0
  8. siada/agent_hub/coder/prompt/__init__.py +0 -0
  9. siada/agent_hub/coder/prompt/base/__init__.py +0 -0
  10. siada/agent_hub/coder/prompt/base/capabilities.py +18 -0
  11. siada/agent_hub/coder/prompt/base/non_interactive.py +14 -0
  12. siada/agent_hub/coder/prompt/base/prompt_builder.py +33 -0
  13. siada/agent_hub/coder/prompt/base/rules.py +40 -0
  14. siada/agent_hub/coder/prompt/base/tool_use.py +14 -0
  15. siada/agent_hub/coder/prompt/bug_prompt/bug_fix_prompt.py +51 -0
  16. siada/agent_hub/coder/prompt/bug_prompt/rules.py +53 -0
  17. siada/agent_hub/coder/prompt/code_gen_prompt.py +45 -0
  18. siada/agent_hub/coder/prompt/fe_gen_prompt.py +45 -0
  19. siada/agent_hub/coder/prompt/issue_review_prompt.py +121 -0
  20. siada/agent_hub/coder/tracing/__init__.py +22 -0
  21. siada/agent_hub/coder/tracing/logger_tracing_processor.py +458 -0
  22. siada/agent_hub/hooks/__init__.py +0 -0
  23. siada/agent_hub/hooks/io_hooks.py +30 -0
  24. siada/agent_hub/siada_agent.py +214 -0
  25. siada/config/__init__.py +0 -0
  26. siada/config/config_loader.py +67 -0
  27. siada/entrypoint/__init__.py +3 -0
  28. siada/entrypoint/args_parser/__init__.py +0 -0
  29. siada/entrypoint/args_parser/args.py +195 -0
  30. siada/entrypoint/interaction/__init__.py +0 -0
  31. siada/entrypoint/interaction/base_turn.py +107 -0
  32. siada/entrypoint/interaction/config.py +30 -0
  33. siada/entrypoint/interaction/controller.py +122 -0
  34. siada/entrypoint/interaction/nointeractive_controller.py +27 -0
  35. siada/entrypoint/interaction/turn/interface.py +116 -0
  36. siada/entrypoint/interaction/turn/models.py +34 -0
  37. siada/entrypoint/interaction/turn/run_turn.py +641 -0
  38. siada/entrypoint/interaction/turn_factory.py +35 -0
  39. siada/entrypoint/interaction/turn_models.py +28 -0
  40. siada/entrypoint/siadahub.py +413 -0
  41. siada/foundation/__init__.py +0 -0
  42. siada/foundation/code_agent_context.py +48 -0
  43. siada/foundation/config.py +59 -0
  44. siada/foundation/constants.py +2 -0
  45. siada/foundation/context.py +76 -0
  46. siada/foundation/logging.py +341 -0
  47. siada/foundation/tools/__init__.py +0 -0
  48. siada/foundation/tools/get_git_diff.py +105 -0
  49. siada/io/__init__.py +0 -0
  50. siada/io/banner.py +148 -0
  51. siada/io/color_settings.py +207 -0
  52. siada/io/color_utils.py +16 -0
  53. siada/io/components/__init__.py +0 -0
  54. siada/io/components/mdstream.py +204 -0
  55. siada/io/console_printer.py +68 -0
  56. siada/io/io.py +661 -0
  57. siada/io/key_bindings.py +129 -0
  58. siada/io/notification_command.py +40 -0
  59. siada/io/test_banner.py +64 -0
  60. siada/models/__init__.py +0 -0
  61. siada/models/agent.py +47 -0
  62. siada/models/coder/__init__.py +0 -0
  63. siada/models/converter.py +27 -0
  64. siada/models/model_base_config.py +121 -0
  65. siada/models/model_run_config.py +153 -0
  66. siada/provider/__init__.py +0 -0
  67. siada/provider/client_factory.py +112 -0
  68. siada/provider/llm_client.py +11 -0
  69. siada/provider/openrouter/__init__.py +0 -0
  70. siada/provider/openrouter/coverter.py +17 -0
  71. siada/provider/openrouter/openroute_provider.py +33 -0
  72. siada/provider/provider_factory.py +53 -0
  73. siada/queries/tree-sitter-language-pack/README.md +7 -0
  74. siada/queries/tree-sitter-language-pack/arduino-tags.scm +5 -0
  75. siada/queries/tree-sitter-language-pack/c-tags.scm +9 -0
  76. siada/queries/tree-sitter-language-pack/chatito-tags.scm +16 -0
  77. siada/queries/tree-sitter-language-pack/commonlisp-tags.scm +122 -0
  78. siada/queries/tree-sitter-language-pack/cpp-tags.scm +15 -0
  79. siada/queries/tree-sitter-language-pack/csharp-tags.scm +26 -0
  80. siada/queries/tree-sitter-language-pack/d-tags.scm +26 -0
  81. siada/queries/tree-sitter-language-pack/dart-tags.scm +92 -0
  82. siada/queries/tree-sitter-language-pack/elisp-tags.scm +5 -0
  83. siada/queries/tree-sitter-language-pack/elixir-tags.scm +54 -0
  84. siada/queries/tree-sitter-language-pack/elm-tags.scm +19 -0
  85. siada/queries/tree-sitter-language-pack/gleam-tags.scm +41 -0
  86. siada/queries/tree-sitter-language-pack/go-tags.scm +42 -0
  87. siada/queries/tree-sitter-language-pack/java-tags.scm +20 -0
  88. siada/queries/tree-sitter-language-pack/javascript-tags.scm +88 -0
  89. siada/queries/tree-sitter-language-pack/lua-tags.scm +34 -0
  90. siada/queries/tree-sitter-language-pack/ocaml-tags.scm +115 -0
  91. siada/queries/tree-sitter-language-pack/ocaml_interface-tags.scm +98 -0
  92. siada/queries/tree-sitter-language-pack/pony-tags.scm +39 -0
  93. siada/queries/tree-sitter-language-pack/properties-tags.scm +5 -0
  94. siada/queries/tree-sitter-language-pack/python-tags.scm +14 -0
  95. siada/queries/tree-sitter-language-pack/r-tags.scm +21 -0
  96. siada/queries/tree-sitter-language-pack/racket-tags.scm +12 -0
  97. siada/queries/tree-sitter-language-pack/ruby-tags.scm +64 -0
  98. siada/queries/tree-sitter-language-pack/rust-tags.scm +60 -0
  99. siada/queries/tree-sitter-language-pack/solidity-tags.scm +43 -0
  100. siada/queries/tree-sitter-language-pack/swift-tags.scm +51 -0
  101. siada/queries/tree-sitter-language-pack/udev-tags.scm +20 -0
  102. siada/queries/tree-sitter-languages/README.md +23 -0
  103. siada/queries/tree-sitter-languages/c-tags.scm +9 -0
  104. siada/queries/tree-sitter-languages/c_sharp-tags.scm +46 -0
  105. siada/queries/tree-sitter-languages/cpp-tags.scm +15 -0
  106. siada/queries/tree-sitter-languages/dart-tags.scm +91 -0
  107. siada/queries/tree-sitter-languages/elisp-tags.scm +8 -0
  108. siada/queries/tree-sitter-languages/elixir-tags.scm +54 -0
  109. siada/queries/tree-sitter-languages/elm-tags.scm +19 -0
  110. siada/queries/tree-sitter-languages/go-tags.scm +30 -0
  111. siada/queries/tree-sitter-languages/hcl-tags.scm +77 -0
  112. siada/queries/tree-sitter-languages/java-tags.scm +20 -0
  113. siada/queries/tree-sitter-languages/javascript-tags.scm +88 -0
  114. siada/queries/tree-sitter-languages/kotlin-tags.scm +27 -0
  115. siada/queries/tree-sitter-languages/ocaml-tags.scm +115 -0
  116. siada/queries/tree-sitter-languages/ocaml_interface-tags.scm +98 -0
  117. siada/queries/tree-sitter-languages/php-tags.scm +26 -0
  118. siada/queries/tree-sitter-languages/python-tags.scm +12 -0
  119. siada/queries/tree-sitter-languages/ql-tags.scm +26 -0
  120. siada/queries/tree-sitter-languages/ruby-tags.scm +64 -0
  121. siada/queries/tree-sitter-languages/rust-tags.scm +60 -0
  122. siada/queries/tree-sitter-languages/scala-tags.scm +65 -0
  123. siada/queries/tree-sitter-languages/typescript-tags.scm +41 -0
  124. siada/services/__init__.py +30 -0
  125. siada/services/at_file_recommendation_design_document.md +1213 -0
  126. siada/services/code_context_manager.py +136 -0
  127. siada/services/enhanced_fix_result_check.py +546 -0
  128. siada/services/execution_trace_collector.py +207 -0
  129. siada/services/file_recommendation/__init__.py +136 -0
  130. siada/services/file_recommendation/core/__init__.py +17 -0
  131. siada/services/file_recommendation/core/completion_engine.py +351 -0
  132. siada/services/file_recommendation/core/config.py +62 -0
  133. siada/services/file_recommendation/core/file_discovery.py +353 -0
  134. siada/services/file_recommendation/core/suggestion.py +110 -0
  135. siada/services/file_recommendation/utils/__init__.py +22 -0
  136. siada/services/file_recommendation/utils/path_utils.py +138 -0
  137. siada/services/file_recommendation/utils/text_utils.py +253 -0
  138. siada/services/fix_result_check.py +377 -0
  139. siada/services/handle_at_command/README.md +247 -0
  140. siada/services/handle_at_command/__init__.py +115 -0
  141. siada/services/handle_at_command/exceptions.py +46 -0
  142. siada/services/handle_at_command/models.py +92 -0
  143. siada/services/handle_at_command/parser.py +189 -0
  144. siada/services/handle_at_command/processor.py +321 -0
  145. siada/services/handle_at_command/resolver.py +318 -0
  146. siada/services/handle_at_command/utils.py +345 -0
  147. siada/services/model_info_service.py +103 -0
  148. siada/services/siada_runner.py +170 -0
  149. siada/session/__init__.py +29 -0
  150. siada/session/session_manager.py +66 -0
  151. siada/session/session_models.py +43 -0
  152. siada/support/__init__.py +0 -0
  153. siada/support/completer.py +204 -0
  154. siada/support/editor.py +146 -0
  155. siada/support/envprocessor.py +54 -0
  156. siada/support/repo.py +51 -0
  157. siada/support/slash_commands.py +410 -0
  158. siada/support/spinner.py +320 -0
  159. siada/tools/__init__.py +0 -0
  160. siada/tools/ast/README.md +345 -0
  161. siada/tools/ast/ast_tool.py +341 -0
  162. siada/tools/ast/models.py +11 -0
  163. siada/tools/coder/__init__.py +0 -0
  164. siada/tools/coder/ask_followup_question.py +70 -0
  165. siada/tools/coder/cmd_runner.py +132 -0
  166. siada/tools/coder/file_operator.py +284 -0
  167. siada/tools/coder/file_search/README.md +223 -0
  168. siada/tools/coder/file_search/__init__.py +10 -0
  169. siada/tools/coder/file_search/bin/rg-linux-arm64 +0 -0
  170. siada/tools/coder/file_search/bin/rg-linux-x64 +0 -0
  171. siada/tools/coder/file_search/bin/rg-macos-arm64 +0 -0
  172. siada/tools/coder/file_search/bin/rg-macos-x64 +0 -0
  173. siada/tools/coder/file_search/bin/rg.exe +0 -0
  174. siada/tools/coder/file_search/search.py +437 -0
  175. siada/tools/coder/file_search/setup_package.py +150 -0
  176. siada/tools/coder/file_search/test_search.py +142 -0
  177. siada/tools/coder/files.py +147 -0
  178. siada/tools/coder/fix_attempt_completion.py +58 -0
  179. siada/tools/coder/issue_review_completion.py +29 -0
  180. siada/tools/coder/observation/__init__.py +0 -0
  181. siada/tools/coder/observation/error.py +22 -0
  182. siada/tools/coder/observation/file_observation.py +216 -0
  183. siada/tools/coder/observation/observation.py +71 -0
  184. siada/tools/coder/repo_map/__init__.py +157 -0
  185. siada/tools/coder/repo_map/dump.py +29 -0
  186. siada/tools/coder/repo_map/io.py +226 -0
  187. siada/tools/coder/repo_map/repo_map.py +881 -0
  188. siada/tools/coder/repo_map/special.py +203 -0
  189. siada/tools/coder/repo_map/token_counter.py +154 -0
  190. siada/tools/coder/repo_map/waiting.py +221 -0
  191. siada/tools/coder/reproduce_completion.py +39 -0
  192. siada/tools/coder/run_cmd.py +60 -0
  193. siada/tools/coder/test_completion.py +25 -0
  194. siada/tools/coder/tool_docs.py +44 -0
  195. siada/tools/compression_tool.py +200 -0
  196. siada/tools/read_many_files/README.md +220 -0
  197. siada/tools/read_many_files/__init__.py +25 -0
  198. siada/tools/read_many_files/file_processor.py +486 -0
  199. siada/tools/read_many_files/filters.py +326 -0
  200. siada/tools/read_many_files/formatters.py +204 -0
  201. siada/tools/read_many_files/models.py +189 -0
  202. siada/tools/read_many_files_tool.py +233 -0
  203. siada/tools/tool_call_format/__init__.py +55 -0
  204. siada/tools/tool_call_format/file_to_language.py +231 -0
  205. siada/tools/tool_call_format/formatter_factory.py +80 -0
  206. siada/tools/tool_call_format/formatters.py +282 -0
  207. siada/tools/tool_call_format/tool_call_formatter.py +54 -0
  208. siada/tools/web/__init__.py +0 -0
  209. siada/tools/web/web_crawl.py +208 -0
  210. siada/utils.py +194 -0
  211. siada_cli-0.0.1.dist-info/LICENSE +201 -0
  212. siada_cli-0.0.1.dist-info/METADATA +457 -0
  213. siada_cli-0.0.1.dist-info/RECORD +215 -0
  214. siada_cli-0.0.1.dist-info/WHEEL +4 -0
  215. siada_cli-0.0.1.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,112 @@
1
+ import os
2
+ import importlib
3
+ from typing import Dict, Any, Tuple
4
+ from siada.provider.llm_client import LLMClient
5
+ import inspect
6
+
7
+ CLIENT_DIR = os.path.dirname(__file__)
8
+ client_map: Dict[str, LLMClient] = {}
9
+
10
+ def _discover_clients():
11
+ """
12
+ Dynamically discovers and registers all LLMClient implementations.
13
+ """
14
+ for item in os.listdir(CLIENT_DIR):
15
+ item_path = os.path.join(CLIENT_DIR, item)
16
+ if os.path.isdir(item_path):
17
+ client_key = item
18
+ for file_name in os.listdir(item_path):
19
+ if file_name.endswith(".py") and file_name != "__init__.py":
20
+ module_name = f"siada.provider.{client_key}.{file_name[:-3]}"
21
+ try:
22
+ module = importlib.import_module(module_name)
23
+ for attr_name in dir(module):
24
+ attr = getattr(module, attr_name)
25
+ if inspect.isclass(attr) and issubclass(attr, LLMClient) and attr is not LLMClient:
26
+ client_map[client_key] = attr()
27
+ except ImportError as e:
28
+ print(f"Error importing client module {module_name}: {e}")
29
+
30
+ _discover_clients()
31
+
32
+ # The client keys are determined dynamically, so we use `str` for type hinting.
33
+ provider_type = str
34
+
35
+
36
+ def get_client(p_type: provider_type | None = None) -> LLMClient:
37
+ """
38
+ Retrieves the LLM client instance based on the client name.
39
+
40
+ Args:
41
+ p_type (provider_type | None): The name of the provider, e.g., 'li', 'openrouter'.
42
+ If None, defaults to the first available client.
43
+
44
+ Returns:
45
+ LLMClient: The corresponding LLM client instance.
46
+
47
+ Raises:
48
+ ValueError: If the client name is not supported.
49
+ """
50
+ if p_type and p_type in client_map:
51
+ return client_map[p_type]
52
+
53
+ raise ValueError("No LLM clients found or registered.")
54
+
55
+
56
+ def build_chat_complete_kwargs(context: Any, default_kwargs: Dict[str, Any]) -> Dict[str, Any]:
57
+ """
58
+ Build chat completion kwargs by merging context parameters with defaults.
59
+
60
+ Args:
61
+ context: Context object that may contain override parameters
62
+ default_kwargs: Default parameters for chat completion
63
+
64
+ Returns:
65
+ Dict[str, Any]: Merged kwargs with context overrides taking precedence
66
+ """
67
+ # Start with default kwargs
68
+ complete_kwargs = default_kwargs.copy()
69
+
70
+ # Override with context parameters if available
71
+ if context and hasattr(context, 'model') and context.model:
72
+ complete_kwargs['model'] = context.model
73
+
74
+ if context and hasattr(context, 'temperature') and context.temperature is not None:
75
+ complete_kwargs['temperature'] = context.temperature
76
+
77
+ if context and hasattr(context, 'stream') and context.stream is not None:
78
+ complete_kwargs['stream'] = context.stream
79
+
80
+ # Add any other context parameters that might be relevant
81
+ if context:
82
+ # Check for additional parameters that might be set on context
83
+ for param in ['max_tokens', 'top_p', 'frequency_penalty', 'presence_penalty']:
84
+ if hasattr(context, param) and getattr(context, param) is not None:
85
+ complete_kwargs[param] = getattr(context, param)
86
+
87
+ return complete_kwargs
88
+
89
+
90
+ def get_client_with_kwargs(context: Any, default_kwargs: Dict[str, Any]) -> Tuple[LLMClient, Dict[str, Any]]:
91
+ """
92
+ Get LLM client and build complete kwargs with context overrides.
93
+
94
+ Args:
95
+ context: Context object containing provider info and optional parameter overrides
96
+ default_kwargs: Default parameters for chat completion
97
+
98
+ Returns:
99
+ Tuple[LLMClient, Dict[str, Any]]: Client instance and merged kwargs
100
+ """
101
+ # Get provider from context
102
+ provider = None
103
+ if context and hasattr(context, 'provider'):
104
+ provider = context.provider
105
+
106
+ # Get the client
107
+ client = get_client(provider)
108
+
109
+ # Build complete kwargs with context overrides
110
+ complete_kwargs = build_chat_complete_kwargs(context, default_kwargs)
111
+
112
+ return client, complete_kwargs
@@ -0,0 +1,11 @@
1
+
2
+
3
+ from litellm.types.utils import ModelResponse as LitellmModelResponse
4
+ from abc import ABC, abstractmethod
5
+
6
+
7
+ class LLMClient(ABC):
8
+
9
+ @abstractmethod
10
+ def completion(self, **kwargs) -> LitellmModelResponse:
11
+ pass
File without changes
@@ -0,0 +1,17 @@
1
+ def covert_to_openrouter_model_name(model_name: str) -> str:
2
+ temp_model_name = model_name
3
+ if model_name.startswith("claude-"):
4
+ temp_model_name = model_name.replace("claude-", "anthropic/claude-")
5
+ elif model_name.startswith("deepseek-"):
6
+ if model_name == "deepseek-v3-0324":
7
+ temp_model_name = "deepseek-chat-v3-0324"
8
+ temp_model_name = temp_model_name.replace("deepseek-", "deepseek/deepseek-")
9
+ elif model_name.startswith("o3-"):
10
+ temp_model_name = model_name.replace("o3-", "openai/o3-")
11
+ elif model_name.startswith("gpt-"):
12
+ temp_model_name = model_name.replace("gpt-", "openai/gpt-")
13
+ elif model_name.startswith("gemini-"):
14
+ temp_model_name = model_name.replace("gemini-", "google/gemini-")
15
+ elif model_name.startswith("kimi-"):
16
+ temp_model_name = model_name.replace("kimi-", "moonshotai/kimi-")
17
+ return f"openrouter/{temp_model_name}"
@@ -0,0 +1,33 @@
1
+ from agents import Model, ModelProvider
2
+ from agents.extensions.models.litellm_model import LitellmModel
3
+ import litellm
4
+
5
+ from siada.provider.llm_client import LLMClient
6
+ from litellm.types.utils import ModelResponse as LitellmModelResponse
7
+
8
+ from siada.provider.openrouter.coverter import covert_to_openrouter_model_name
9
+
10
+
11
+ class OpenRouterProvider(ModelProvider):
12
+ """implementation of ModelProvider for OpenRouter by litellm"""
13
+
14
+ def get_model(self, model_name: str | None) -> Model:
15
+ """Get a model by name.
16
+
17
+ Args:
18
+ model_name: The name of the model to get.
19
+
20
+ Returns:
21
+ The model.
22
+ """
23
+
24
+ covert_model_name = covert_to_openrouter_model_name(model_name)
25
+ return LitellmModel(model=covert_model_name)
26
+
27
+
28
+ class OpenRouterClient(LLMClient):
29
+
30
+ def completion(self, **kwargs) -> LitellmModelResponse:
31
+ model = kwargs.get("model")
32
+ kwargs["model"] = covert_to_openrouter_model_name(model)
33
+ return litellm.completion(**kwargs)
@@ -0,0 +1,53 @@
1
+ import os
2
+ import importlib
3
+ from typing import Dict, Type
4
+ from agents import ModelProvider
5
+ import inspect
6
+
7
+ PROVIDER_DIR = os.path.dirname(__file__)
8
+ provider_map: Dict[str, ModelProvider] = {}
9
+
10
+ def _discover_providers():
11
+ """
12
+ Dynamically discovers and registers all ModelProvider implementations.
13
+ """
14
+ for item in os.listdir(PROVIDER_DIR):
15
+ item_path = os.path.join(PROVIDER_DIR, item)
16
+ if os.path.isdir(item_path):
17
+ provider_key = item
18
+ for file_name in os.listdir(item_path):
19
+ if file_name.endswith("_provider.py"):
20
+ module_name = f"siada.provider.{provider_key}.{file_name[:-3]}"
21
+ try:
22
+ module = importlib.import_module(module_name)
23
+ for attr_name in dir(module):
24
+ attr = getattr(module, attr_name)
25
+ if inspect.isclass(attr) and issubclass(attr, ModelProvider) and attr is not ModelProvider:
26
+ provider_map[provider_key] = attr()
27
+ except ImportError as e:
28
+ print(f"Error importing provider module {module_name}: {e}")
29
+
30
+ _discover_providers()
31
+
32
+ # The provider keys are determined dynamically, so we use `str` for type hinting.
33
+ provider_type = str
34
+
35
+
36
+ def get_provider(p_type: provider_type | None = None) -> ModelProvider:
37
+ """
38
+ Retrieves the model provider instance based on the provider name.
39
+
40
+ Args:
41
+ p_type (provider_type | None): The name of the provider, e.g., 'li'.
42
+ If None, defaults to the first available provider.
43
+
44
+ Returns:
45
+ ModelProvider: The corresponding model provider instance.
46
+
47
+ Raises:
48
+ ValueError: If the provider name is not supported.
49
+ """
50
+ if p_type and p_type in provider_map:
51
+ return provider_map[p_type]
52
+
53
+ raise ValueError("No model providers found or registered.")
@@ -0,0 +1,7 @@
1
+ These scm files are all adapted from the github repositories listed here:
2
+
3
+ https://github.com/Goldziher/tree-sitter-language-pack/blob/main/sources/language_definitions.json
4
+
5
+ See this URL for information on the licenses of each repo:
6
+
7
+ https://github.com/Goldziher/tree-sitter-language-pack/
@@ -0,0 +1,5 @@
1
+ (function_declarator
2
+ declarator: (identifier) @name.definition.function) @definition.function
3
+
4
+ (call_expression
5
+ function: (identifier) @name.reference.call) @reference.call
@@ -0,0 +1,9 @@
1
+ (struct_specifier name: (type_identifier) @name.definition.class body:(_)) @definition.class
2
+
3
+ (declaration type: (union_specifier name: (type_identifier) @name.definition.class)) @definition.class
4
+
5
+ (function_declarator declarator: (identifier) @name.definition.function) @definition.function
6
+
7
+ (type_definition declarator: (type_identifier) @name.definition.type) @definition.type
8
+
9
+ (enum_specifier name: (type_identifier) @name.definition.type) @definition.type
@@ -0,0 +1,16 @@
1
+ ; Definitions
2
+ (intent_def
3
+ (intent) @name.definition.intent) @definition.intent
4
+
5
+ (slot_def
6
+ (slot) @name.definition.slot) @definition.slot
7
+
8
+ (alias_def
9
+ (alias) @name.definition.alias) @definition.alias
10
+
11
+ ; References
12
+ (slot_ref
13
+ (slot) @name.reference.slot) @reference.slot
14
+
15
+ (alias_ref
16
+ (alias) @name.reference.alias) @reference.alias
@@ -0,0 +1,122 @@
1
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
+ ;;; Function Definitions ;;;;;;;;;;;;;;;;;;;;;;;
3
+
4
+ (defun_header
5
+ function_name: (sym_lit) @name.definition.function) @definition.function
6
+
7
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
+ ;;; Function Calls ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
+ ;;;
10
+ ;;; Basically, we consider every list literal with symbol as the
11
+ ;;; first element to be a call to a function named by that element.
12
+ ;;; But we must exclude some cases. Note, tree-sitter @ignore
13
+ ;;; cases only work if they are declared before the cases
14
+ ;;; we want to include.
15
+
16
+ ;; Exclude lambda lists for function definitions
17
+ ;; For example:
18
+ ;;
19
+ ;; (defun my-func (arg1 arg2) ...)
20
+ ;;
21
+ ;; do not treat (arg1 arg2) as a call of function arg1
22
+ ;;
23
+ (defun_header
24
+ lambda_list: (list_lit . [(sym_lit) (package_lit)] @ignore))
25
+
26
+ ;; Similar to the above, but for
27
+ ;;
28
+ ;; (defmethod m ((type1 param1) (type2 param2)) ...)
29
+ ;;
30
+ ;; where list literals having symbol as their first element
31
+ ;; are nested inside the lambda list.
32
+ (defun_header
33
+ lambda_list: (list_lit (list_lit . [(sym_lit) (package_lit)] @ignore)))
34
+
35
+ ;;
36
+ ;; (let ((var ...) (var2 ...)) ...)
37
+ ;;
38
+ ;; - exclude var, var2
39
+ ;; - the same for let*, flet, labels, macrolet, symbol-macrolet
40
+ (list_lit . [(sym_lit) (package_lit)] @name.reference.call
41
+ . (list_lit (list_lit . [(sym_lit) (package_lit)] @ignore))
42
+ (#match? @name.reference.call
43
+ "(?i)^(cl:)?(let|let\\*|flet|labels|macrolet|symbol-macrolet)$")
44
+ )
45
+
46
+ ;; TODO:
47
+ ;; - exclude also:
48
+ ;; - (defclass name (parent parent2)
49
+ ;; ((slot1 ...)
50
+ ;; (slot2 ...))
51
+ ;; exclude the parent, slot1, slot2
52
+ ;; - (flet ((func-1 (param1 param2))) ...)
53
+ ;; - we already exclude func-1, but param1 is still recognized
54
+ ;; as a function call - exclude it too
55
+ ;; - the same for labels
56
+ ;; - the same macrolet
57
+ ;; - what else?
58
+ ;; (that's a non-goal to completely support all macros
59
+ ;; and special operators, but every one we support
60
+ ;; makes the solution a little bit better)
61
+ ;; - (flet ((func-1 (param1 param2))) ...)
62
+ ;; - instead of simply excluding it, as we do today,
63
+ ;; tag func-1 as @local.definition.function (I suppose)
64
+ ;; - the same for labels, macrolet
65
+ ;; - @local.scope for let, let*, flet, labels, macrolet
66
+ ;; - I guess the whole span of the scope text,
67
+ ;; till the closing paren, should be tagged as @local.scope;
68
+ ;; Hopefully, combined with @local.definition.function
69
+ ;; within the scope, the usual @reference.call within
70
+ ;; that scope will refer to the local definition,
71
+ ;; and there will be no need to use @local.reference.call
72
+ ;; (which is more difficult to implement).
73
+ ;; - When implementing, remember the scope rules differences
74
+ ;; of let vs let*, flet vs labels.
75
+
76
+
77
+ ;; Include all other cases - list literal with symbol as the
78
+ ;; first element
79
+ (list_lit . [(sym_lit) (package_lit)] @name.reference.call) @reference.call
80
+
81
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
82
+ ;;; classes
83
+
84
+ (list_lit . [(sym_lit) (package_lit)] @ignore
85
+ . [(sym_lit) (package_lit)] @name.definition.class
86
+ (#match? @ignore "(?i)^(cl:)?defclass$")
87
+ ) @definition.class
88
+
89
+ (list_lit . [(sym_lit) (package_lit)] @ignore
90
+ . (quoting_lit [(sym_lit) (package_lit)] @name.reference.class)
91
+ (#match? @ignore "(?i)^(cl:)?make-instance$")
92
+ ) @reference.class
93
+
94
+ ;;; TODO:
95
+ ;; - @reference.class for base classes
96
+
97
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
98
+ ;;; TODO:
99
+ ;; - Symbols referenced in defpackage
100
+ ;;
101
+ ;; (defpackage ...
102
+ ;; (:export (symbol-a :symbol-b #:symbol-c "SYMBOL-D")))
103
+ ;;
104
+ ;; The goal is to allow quick navigation from the API
105
+ ;; overview in the form of defpackage, to the definition
106
+ ;; where user can read parameters, docstring, etc.
107
+ ;; - The @name must not include the colon, or sharpsign colon, quotes,
108
+ ;; just symbol-a, symbol-b, symbol-c, sybmol-d
109
+ ;; - Downcase the names specified as string literals?
110
+ ;; ("SYMBOL-D" -> symbol-d)
111
+ ;; - We don't know if the exported symbol is a function, variable,
112
+ ;; class or something else. The official doc
113
+ ;; (https://tree-sitter.github.io/tree-sitter/code-navigation-systems)
114
+ ;; does not even suggest a tag for variable reference.
115
+ ;; (Although in practice, the `tree-sitter tags` command
116
+ ;; allows any @reference.* and @definition.* tags)
117
+ ;; Probably it's better to just use @reference.call for all
118
+ ;; the symbols in the :export clause.
119
+ ;;
120
+ ;; - The same for the export function call:
121
+ ;;
122
+ ;; (export '(symbol-a :symbol-b #:symbol-c "SYMBOL-D"))
@@ -0,0 +1,15 @@
1
+ (struct_specifier name: (type_identifier) @name.definition.class body:(_)) @definition.class
2
+
3
+ (declaration type: (union_specifier name: (type_identifier) @name.definition.class)) @definition.class
4
+
5
+ (function_declarator declarator: (identifier) @name.definition.function) @definition.function
6
+
7
+ (function_declarator declarator: (field_identifier) @name.definition.function) @definition.function
8
+
9
+ (function_declarator declarator: (qualified_identifier scope: (namespace_identifier) @local.scope name: (identifier) @name.definition.method)) @definition.method
10
+
11
+ (type_definition declarator: (type_identifier) @name.definition.type) @definition.type
12
+
13
+ (enum_specifier name: (type_identifier) @name.definition.type) @definition.type
14
+
15
+ (class_specifier name: (type_identifier) @name.definition.class) @definition.class
@@ -0,0 +1,26 @@
1
+ ; Based on https://github.com/tree-sitter/tree-sitter-c-sharp/blob/master/queries/tags.scm
2
+ ; MIT License.
3
+
4
+ (class_declaration name: (identifier) @name.definition.class) @definition.class
5
+
6
+ (class_declaration (base_list (_) @name.reference.class)) @reference.class
7
+
8
+ (interface_declaration name: (identifier) @name.definition.interface) @definition.interface
9
+
10
+ (interface_declaration (base_list (_) @name.reference.interface)) @reference.interface
11
+
12
+ (method_declaration name: (identifier) @name.definition.method) @definition.method
13
+
14
+ (object_creation_expression type: (identifier) @name.reference.class) @reference.class
15
+
16
+ (type_parameter_constraints_clause (identifier) @name.reference.class) @reference.class
17
+
18
+ (type_parameter_constraint (type type: (identifier) @name.reference.class)) @reference.class
19
+
20
+ (variable_declaration type: (identifier) @name.reference.class) @reference.class
21
+
22
+ (invocation_expression function: (member_access_expression name: (identifier) @name.reference.send)) @reference.send
23
+
24
+ (namespace_declaration name: (identifier) @name.definition.module) @definition.module
25
+
26
+ (namespace_declaration name: (identifier) @name.definition.module) @module
@@ -0,0 +1,26 @@
1
+ (module_def (module_declaration (module_fqn) @name.definition.module)) @definition.module
2
+
3
+ (struct_declaration (struct) . (identifier) @name.definition.class) @definition.class
4
+ (interface_declaration (interface) . (identifier) @name.definition.interface) @definition.interface
5
+ (enum_declaration (enum) . (identifier) @name.definition.type) @definition.type
6
+
7
+ (class_declaration (class) . (identifier) @name.definition.class) @definition.class
8
+ (constructor (this) @name.definition.method) @definition.method
9
+ (destructor (this) @name.definition.method) @definition.method
10
+ (postblit (this) @name.definition.method) @definition.method
11
+
12
+ (manifest_declarator . (identifier) @name.definition.type) @definition.type
13
+
14
+ (function_declaration (identifier) @name.definition.function) @definition.function
15
+
16
+ (union_declaration (union) . (identifier) @name.definition.type) @definition.type
17
+
18
+ (anonymous_enum_declaration (enum_member . (identifier) @name.definition.constant)) @definition.constant
19
+
20
+ (enum_declaration (enum_member . (identifier) @name.definition.constant)) @definition.constant
21
+
22
+ (call_expression (identifier) @name.reference.call) @reference.call
23
+ (call_expression (type (template_instance (identifier) @name.reference.call))) @reference.call
24
+ (parameter (type (identifier) @name.reference.class) @reference.class (identifier))
25
+
26
+ (variable_declaration (type (identifier) @name.reference.class) @reference.class (declarator))
@@ -0,0 +1,92 @@
1
+
2
+ (class_definition
3
+ name: (identifier) @name.definition.class) @definition.class
4
+
5
+ (method_signature
6
+ (function_signature)) @definition.method
7
+
8
+ (type_alias
9
+ (type_identifier) @name.definition.type) @definition.type
10
+
11
+ (method_signature
12
+ (getter_signature
13
+ name: (identifier) @name.definition.method)) @definition.method
14
+
15
+ (method_signature
16
+ (setter_signature
17
+ name: (identifier) @name.definition.method)) @definition.method
18
+
19
+ (method_signature
20
+ (function_signature
21
+ name: (identifier) @name.definition.method)) @definition.method
22
+
23
+ (method_signature
24
+ (factory_constructor_signature
25
+ (identifier) @name.definition.method)) @definition.method
26
+
27
+ (method_signature
28
+ (constructor_signature
29
+ name: (identifier) @name.definition.method)) @definition.method
30
+
31
+ (method_signature
32
+ (operator_signature)) @definition.method
33
+
34
+ (method_signature) @definition.method
35
+
36
+ (mixin_declaration
37
+ (mixin)
38
+ (identifier) @name.definition.mixin) @definition.mixin
39
+
40
+ (extension_declaration
41
+ name: (identifier) @name.definition.extension) @definition.extension
42
+
43
+
44
+ (new_expression
45
+ (type_identifier) @name.reference.class) @reference.class
46
+
47
+ (enum_declaration
48
+ name: (identifier) @name.definition.enum) @definition.enum
49
+
50
+ (function_signature
51
+ name: (identifier) @name.definition.function) @definition.function
52
+
53
+ (initialized_variable_definition
54
+ name: (identifier)
55
+ value: (identifier) @name.reference.class
56
+ value: (selector
57
+ "!"?
58
+ (argument_part
59
+ (arguments
60
+ (argument)*))?)?) @reference.class
61
+
62
+ (assignment_expression
63
+ left: (assignable_expression
64
+ (identifier)
65
+ (unconditional_assignable_selector
66
+ "."
67
+ (identifier) @name.reference.send))) @reference.call
68
+
69
+ (assignment_expression
70
+ left: (assignable_expression
71
+ (identifier)
72
+ (conditional_assignable_selector
73
+ "?."
74
+ (identifier) @name.reference.send))) @reference.call
75
+
76
+ ((identifier) @name.reference.send
77
+ (selector
78
+ "!"?
79
+ (conditional_assignable_selector
80
+ "?." (identifier) @name.reference.send)?
81
+ (unconditional_assignable_selector
82
+ "."? (identifier) @name.reference.send)?
83
+ (argument_part
84
+ (arguments
85
+ (argument)*))?)*
86
+ (cascade_section
87
+ (cascade_selector
88
+ (identifier)) @name.reference.send
89
+ (argument_part
90
+ (arguments
91
+ (argument)*))?)?) @reference.call
92
+
@@ -0,0 +1,5 @@
1
+ ;; defun/defsubst
2
+ (function_definition name: (symbol) @name.definition.function) @definition.function
3
+
4
+ ;; Treat macros as function definitions for the sake of TAGS.
5
+ (macro_definition name: (symbol) @name.definition.function) @definition.function
@@ -0,0 +1,54 @@
1
+ ; Definitions
2
+
3
+ ; * modules and protocols
4
+ (call
5
+ target: (identifier) @ignore
6
+ (arguments (alias) @name.definition.module)
7
+ (#any-of? @ignore "defmodule" "defprotocol")) @definition.module
8
+
9
+ ; * functions/macros
10
+ (call
11
+ target: (identifier) @ignore
12
+ (arguments
13
+ [
14
+ ; zero-arity functions with no parentheses
15
+ (identifier) @name.definition.function
16
+ ; regular function clause
17
+ (call target: (identifier) @name.definition.function)
18
+ ; function clause with a guard clause
19
+ (binary_operator
20
+ left: (call target: (identifier) @name.definition.function)
21
+ operator: "when")
22
+ ])
23
+ (#any-of? @ignore "def" "defp" "defdelegate" "defguard" "defguardp" "defmacro" "defmacrop" "defn" "defnp")) @definition.function
24
+
25
+ ; References
26
+
27
+ ; ignore calls to kernel/special-forms keywords
28
+ (call
29
+ target: (identifier) @ignore
30
+ (#any-of? @ignore "def" "defp" "defdelegate" "defguard" "defguardp" "defmacro" "defmacrop" "defn" "defnp" "defmodule" "defprotocol" "defimpl" "defstruct" "defexception" "defoverridable" "alias" "case" "cond" "else" "for" "if" "import" "quote" "raise" "receive" "require" "reraise" "super" "throw" "try" "unless" "unquote" "unquote_splicing" "use" "with"))
31
+
32
+ ; ignore module attributes
33
+ (unary_operator
34
+ operator: "@"
35
+ operand: (call
36
+ target: (identifier) @ignore))
37
+
38
+ ; * function call
39
+ (call
40
+ target: [
41
+ ; local
42
+ (identifier) @name.reference.call
43
+ ; remote
44
+ (dot
45
+ right: (identifier) @name.reference.call)
46
+ ]) @reference.call
47
+
48
+ ; * pipe into function call
49
+ (binary_operator
50
+ operator: "|>"
51
+ right: (identifier) @name.reference.call) @reference.call
52
+
53
+ ; * modules
54
+ (alias) @name.reference.module @reference.module
@@ -0,0 +1,19 @@
1
+ (value_declaration (function_declaration_left (lower_case_identifier) @name.definition.function)) @definition.function
2
+
3
+ (function_call_expr (value_expr (value_qid) @name.reference.function)) @reference.function
4
+ (exposed_value (lower_case_identifier) @name.reference.function) @reference.function
5
+ (type_annotation ((lower_case_identifier) @name.reference.function) (colon)) @reference.function
6
+
7
+ (type_declaration ((upper_case_identifier) @name.definition.type) ) @definition.type
8
+
9
+ (type_ref (upper_case_qid (upper_case_identifier) @name.reference.type)) @reference.type
10
+ (exposed_type (upper_case_identifier) @name.reference.type) @reference.type
11
+
12
+ (type_declaration (union_variant (upper_case_identifier) @name.definition.union)) @definition.union
13
+
14
+ (value_expr (upper_case_qid (upper_case_identifier) @name.reference.union)) @reference.union
15
+
16
+
17
+ (module_declaration
18
+ (upper_case_qid (upper_case_identifier)) @name.definition.module
19
+ ) @definition.module