@nogataka/smart-edit 0.0.14
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.
- package/LICENSE +22 -0
- package/README.md +244 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +7 -0
- package/dist/devtools/generate_prompt_factory.d.ts +5 -0
- package/dist/devtools/generate_prompt_factory.js +114 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +34 -0
- package/dist/interprompt/index.d.ts +2 -0
- package/dist/interprompt/index.js +1 -0
- package/dist/interprompt/jinja_template.d.ts +10 -0
- package/dist/interprompt/jinja_template.js +174 -0
- package/dist/interprompt/multilang_prompt.d.ts +54 -0
- package/dist/interprompt/multilang_prompt.js +302 -0
- package/dist/interprompt/prompt_factory.d.ts +16 -0
- package/dist/interprompt/prompt_factory.js +189 -0
- package/dist/interprompt/util/class_decorators.d.ts +1 -0
- package/dist/interprompt/util/class_decorators.js +1 -0
- package/dist/interprompt/util/index.d.ts +1 -0
- package/dist/interprompt/util/index.js +1 -0
- package/dist/serena/agent.d.ts +118 -0
- package/dist/serena/agent.js +675 -0
- package/dist/serena/agno.d.ts +111 -0
- package/dist/serena/agno.js +278 -0
- package/dist/serena/analytics.d.ts +24 -0
- package/dist/serena/analytics.js +119 -0
- package/dist/serena/cli.d.ts +9 -0
- package/dist/serena/cli.js +731 -0
- package/dist/serena/code_editor.d.ts +42 -0
- package/dist/serena/code_editor.js +239 -0
- package/dist/serena/config/context_mode.d.ts +41 -0
- package/dist/serena/config/context_mode.js +239 -0
- package/dist/serena/config/serena_config.d.ts +134 -0
- package/dist/serena/config/serena_config.js +718 -0
- package/dist/serena/constants.d.ts +18 -0
- package/dist/serena/constants.js +27 -0
- package/dist/serena/dashboard.d.ts +55 -0
- package/dist/serena/dashboard.js +472 -0
- package/dist/serena/generated/generated_prompt_factory.d.ts +27 -0
- package/dist/serena/generated/generated_prompt_factory.js +42 -0
- package/dist/serena/gui_log_viewer.d.ts +41 -0
- package/dist/serena/gui_log_viewer.js +436 -0
- package/dist/serena/mcp.d.ts +118 -0
- package/dist/serena/mcp.js +904 -0
- package/dist/serena/project.d.ts +62 -0
- package/dist/serena/project.js +321 -0
- package/dist/serena/prompt_factory.d.ts +20 -0
- package/dist/serena/prompt_factory.js +42 -0
- package/dist/serena/resources/config/contexts/agent.yml +8 -0
- package/dist/serena/resources/config/contexts/chatgpt.yml +28 -0
- package/dist/serena/resources/config/contexts/codex.yml +27 -0
- package/dist/serena/resources/config/contexts/context.template.yml +11 -0
- package/dist/serena/resources/config/contexts/desktop-app.yml +17 -0
- package/dist/serena/resources/config/contexts/ide-assistant.yml +26 -0
- package/dist/serena/resources/config/contexts/oaicompat-agent.yml +8 -0
- package/dist/serena/resources/config/internal_modes/jetbrains.yml +15 -0
- package/dist/serena/resources/config/modes/editing.yml +112 -0
- package/dist/serena/resources/config/modes/interactive.yml +11 -0
- package/dist/serena/resources/config/modes/mode.template.yml +7 -0
- package/dist/serena/resources/config/modes/no-onboarding.yml +8 -0
- package/dist/serena/resources/config/modes/onboarding.yml +16 -0
- package/dist/serena/resources/config/modes/one-shot.yml +15 -0
- package/dist/serena/resources/config/modes/planning.yml +15 -0
- package/dist/serena/resources/config/prompt_templates/simple_tool_outputs.yml +75 -0
- package/dist/serena/resources/config/prompt_templates/system_prompt.yml +66 -0
- package/dist/serena/resources/dashboard/dashboard.js +815 -0
- package/dist/serena/resources/dashboard/index.html +314 -0
- package/dist/serena/resources/dashboard/jquery.min.js +3 -0
- package/dist/serena/resources/dashboard/serena-icon-16.png +0 -0
- package/dist/serena/resources/dashboard/serena-icon-32.png +0 -0
- package/dist/serena/resources/dashboard/serena-icon-48.png +0 -0
- package/dist/serena/resources/dashboard/serena-logs-dark-mode.png +0 -0
- package/dist/serena/resources/dashboard/serena-logs.png +0 -0
- package/dist/serena/resources/project.template.yml +67 -0
- package/dist/serena/resources/serena_config.template.yml +85 -0
- package/dist/serena/symbol.d.ts +199 -0
- package/dist/serena/symbol.js +616 -0
- package/dist/serena/text_utils.d.ts +51 -0
- package/dist/serena/text_utils.js +267 -0
- package/dist/serena/tools/cmd_tools.d.ts +31 -0
- package/dist/serena/tools/cmd_tools.js +48 -0
- package/dist/serena/tools/config_tools.d.ts +53 -0
- package/dist/serena/tools/config_tools.js +176 -0
- package/dist/serena/tools/file_tools.d.ts +231 -0
- package/dist/serena/tools/file_tools.js +511 -0
- package/dist/serena/tools/index.d.ts +7 -0
- package/dist/serena/tools/index.js +7 -0
- package/dist/serena/tools/memory_tools.d.ts +60 -0
- package/dist/serena/tools/memory_tools.js +135 -0
- package/dist/serena/tools/symbol_tools.d.ts +165 -0
- package/dist/serena/tools/symbol_tools.js +362 -0
- package/dist/serena/tools/tools_base.d.ts +162 -0
- package/dist/serena/tools/tools_base.js +378 -0
- package/dist/serena/tools/workflow_tools.d.ts +35 -0
- package/dist/serena/tools/workflow_tools.js +161 -0
- package/dist/serena/util/class_decorators.d.ts +7 -0
- package/dist/serena/util/class_decorators.js +37 -0
- package/dist/serena/util/exception.d.ts +8 -0
- package/dist/serena/util/exception.js +53 -0
- package/dist/serena/util/file_system.d.ts +30 -0
- package/dist/serena/util/file_system.js +352 -0
- package/dist/serena/util/general.d.ts +11 -0
- package/dist/serena/util/general.js +42 -0
- package/dist/serena/util/git.d.ts +11 -0
- package/dist/serena/util/git.js +37 -0
- package/dist/serena/util/inspection.d.ts +45 -0
- package/dist/serena/util/inspection.js +221 -0
- package/dist/serena/util/logging.d.ts +46 -0
- package/dist/serena/util/logging.js +205 -0
- package/dist/serena/util/shell.d.ts +21 -0
- package/dist/serena/util/shell.js +95 -0
- package/dist/serena/util/thread.d.ts +23 -0
- package/dist/serena/util/thread.js +88 -0
- package/dist/serena/version.d.ts +1 -0
- package/dist/serena/version.js +23 -0
- package/dist/solidlsp/language_servers/autoload.d.ts +23 -0
- package/dist/solidlsp/language_servers/autoload.js +25 -0
- package/dist/solidlsp/language_servers/bash_language_server.d.ts +10 -0
- package/dist/solidlsp/language_servers/bash_language_server.js +64 -0
- package/dist/solidlsp/language_servers/clangd_language_server.d.ts +13 -0
- package/dist/solidlsp/language_servers/clangd_language_server.js +110 -0
- package/dist/solidlsp/language_servers/clojure_lsp.d.ts +13 -0
- package/dist/solidlsp/language_servers/clojure_lsp.js +137 -0
- package/dist/solidlsp/language_servers/common.d.ts +41 -0
- package/dist/solidlsp/language_servers/common.js +365 -0
- package/dist/solidlsp/language_servers/csharp_language_server.d.ts +21 -0
- package/dist/solidlsp/language_servers/csharp_language_server.js +694 -0
- package/dist/solidlsp/language_servers/dart_language_server.d.ts +10 -0
- package/dist/solidlsp/language_servers/dart_language_server.js +122 -0
- package/dist/solidlsp/language_servers/eclipse_jdtls.d.ts +24 -0
- package/dist/solidlsp/language_servers/eclipse_jdtls.js +671 -0
- package/dist/solidlsp/language_servers/erlang_language_server.d.ts +22 -0
- package/dist/solidlsp/language_servers/erlang_language_server.js +327 -0
- package/dist/solidlsp/language_servers/gopls.d.ts +12 -0
- package/dist/solidlsp/language_servers/gopls.js +59 -0
- package/dist/solidlsp/language_servers/intelephense.d.ts +13 -0
- package/dist/solidlsp/language_servers/intelephense.js +121 -0
- package/dist/solidlsp/language_servers/jedi_server.d.ts +18 -0
- package/dist/solidlsp/language_servers/jedi_server.js +234 -0
- package/dist/solidlsp/language_servers/kotlin_language_server.d.ts +19 -0
- package/dist/solidlsp/language_servers/kotlin_language_server.js +474 -0
- package/dist/solidlsp/language_servers/lua_ls.d.ts +18 -0
- package/dist/solidlsp/language_servers/lua_ls.js +319 -0
- package/dist/solidlsp/language_servers/nixd_language_server.d.ts +17 -0
- package/dist/solidlsp/language_servers/nixd_language_server.js +341 -0
- package/dist/solidlsp/language_servers/pyright_server.d.ts +19 -0
- package/dist/solidlsp/language_servers/pyright_server.js +180 -0
- package/dist/solidlsp/language_servers/r_language_server.d.ts +19 -0
- package/dist/solidlsp/language_servers/r_language_server.js +184 -0
- package/dist/solidlsp/language_servers/ruby_common.d.ts +10 -0
- package/dist/solidlsp/language_servers/ruby_common.js +136 -0
- package/dist/solidlsp/language_servers/ruby_lsp.d.ts +18 -0
- package/dist/solidlsp/language_servers/ruby_lsp.js +230 -0
- package/dist/solidlsp/language_servers/rust_analyzer.d.ts +13 -0
- package/dist/solidlsp/language_servers/rust_analyzer.js +96 -0
- package/dist/solidlsp/language_servers/solargraph.d.ts +18 -0
- package/dist/solidlsp/language_servers/solargraph.js +208 -0
- package/dist/solidlsp/language_servers/sourcekit_lsp.d.ts +24 -0
- package/dist/solidlsp/language_servers/sourcekit_lsp.js +449 -0
- package/dist/solidlsp/language_servers/terraform_ls.d.ts +13 -0
- package/dist/solidlsp/language_servers/terraform_ls.js +139 -0
- package/dist/solidlsp/language_servers/typescript_language_server.d.ts +20 -0
- package/dist/solidlsp/language_servers/typescript_language_server.js +237 -0
- package/dist/solidlsp/language_servers/vts_language_server.d.ts +13 -0
- package/dist/solidlsp/language_servers/vts_language_server.js +121 -0
- package/dist/solidlsp/language_servers/zls.d.ts +20 -0
- package/dist/solidlsp/language_servers/zls.js +254 -0
- package/dist/solidlsp/ls.d.ts +197 -0
- package/dist/solidlsp/ls.js +507 -0
- package/dist/solidlsp/ls_config.d.ts +43 -0
- package/dist/solidlsp/ls_config.js +157 -0
- package/dist/solidlsp/ls_exceptions.d.ts +5 -0
- package/dist/solidlsp/ls_exceptions.js +14 -0
- package/dist/solidlsp/ls_handler.d.ts +54 -0
- package/dist/solidlsp/ls_handler.js +406 -0
- package/dist/solidlsp/ls_request.d.ts +31 -0
- package/dist/solidlsp/ls_request.js +42 -0
- package/dist/solidlsp/ls_types.d.ts +7 -0
- package/dist/solidlsp/ls_types.js +8 -0
- package/dist/solidlsp/lsp_protocol_handler/server.d.ts +61 -0
- package/dist/solidlsp/lsp_protocol_handler/server.js +68 -0
- package/dist/solidlsp/util/subprocess_util.d.ts +6 -0
- package/dist/solidlsp/util/subprocess_util.js +11 -0
- package/dist/solidlsp/util/zip.d.ts +25 -0
- package/dist/solidlsp/util/zip.js +188 -0
- package/package.json +65 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createSerenaLogger } from './util/logging.js';
|
|
3
|
+
const { logger } = createSerenaLogger({ name: 'serena.symbol', emitToConsole: false, level: 'info' });
|
|
4
|
+
export var SymbolKind;
|
|
5
|
+
(function (SymbolKind) {
|
|
6
|
+
SymbolKind[SymbolKind["File"] = 1] = "File";
|
|
7
|
+
SymbolKind[SymbolKind["Module"] = 2] = "Module";
|
|
8
|
+
SymbolKind[SymbolKind["Namespace"] = 3] = "Namespace";
|
|
9
|
+
SymbolKind[SymbolKind["Package"] = 4] = "Package";
|
|
10
|
+
SymbolKind[SymbolKind["Class"] = 5] = "Class";
|
|
11
|
+
SymbolKind[SymbolKind["Method"] = 6] = "Method";
|
|
12
|
+
SymbolKind[SymbolKind["Property"] = 7] = "Property";
|
|
13
|
+
SymbolKind[SymbolKind["Field"] = 8] = "Field";
|
|
14
|
+
SymbolKind[SymbolKind["Constructor"] = 9] = "Constructor";
|
|
15
|
+
SymbolKind[SymbolKind["Enum"] = 10] = "Enum";
|
|
16
|
+
SymbolKind[SymbolKind["Interface"] = 11] = "Interface";
|
|
17
|
+
SymbolKind[SymbolKind["Function"] = 12] = "Function";
|
|
18
|
+
SymbolKind[SymbolKind["Variable"] = 13] = "Variable";
|
|
19
|
+
SymbolKind[SymbolKind["Constant"] = 14] = "Constant";
|
|
20
|
+
SymbolKind[SymbolKind["String"] = 15] = "String";
|
|
21
|
+
SymbolKind[SymbolKind["Number"] = 16] = "Number";
|
|
22
|
+
SymbolKind[SymbolKind["Boolean"] = 17] = "Boolean";
|
|
23
|
+
SymbolKind[SymbolKind["Array"] = 18] = "Array";
|
|
24
|
+
SymbolKind[SymbolKind["Object"] = 19] = "Object";
|
|
25
|
+
SymbolKind[SymbolKind["Key"] = 20] = "Key";
|
|
26
|
+
SymbolKind[SymbolKind["Null"] = 21] = "Null";
|
|
27
|
+
SymbolKind[SymbolKind["EnumMember"] = 22] = "EnumMember";
|
|
28
|
+
SymbolKind[SymbolKind["Struct"] = 23] = "Struct";
|
|
29
|
+
SymbolKind[SymbolKind["Event"] = 24] = "Event";
|
|
30
|
+
SymbolKind[SymbolKind["Operator"] = 25] = "Operator";
|
|
31
|
+
SymbolKind[SymbolKind["TypeParameter"] = 26] = "TypeParameter";
|
|
32
|
+
})(SymbolKind || (SymbolKind = {}));
|
|
33
|
+
export class LanguageServerSymbolLocation {
|
|
34
|
+
relativePath;
|
|
35
|
+
line;
|
|
36
|
+
column;
|
|
37
|
+
constructor(init) {
|
|
38
|
+
this.relativePath = init.relativePath ? init.relativePath.replace(/\//g, path.sep) : null;
|
|
39
|
+
this.line = init.line ?? null;
|
|
40
|
+
this.column = init.column ?? null;
|
|
41
|
+
}
|
|
42
|
+
toDict(options = {}) {
|
|
43
|
+
const includeRelativePath = options.includeRelativePath ?? true;
|
|
44
|
+
const payload = {
|
|
45
|
+
relative_path: includeRelativePath ? this.relativePath : undefined,
|
|
46
|
+
line: this.line,
|
|
47
|
+
column: this.column
|
|
48
|
+
};
|
|
49
|
+
if (!includeRelativePath) {
|
|
50
|
+
delete payload.relative_path;
|
|
51
|
+
}
|
|
52
|
+
return payload;
|
|
53
|
+
}
|
|
54
|
+
to_dict(options) {
|
|
55
|
+
return this.toDict({ includeRelativePath: options?.include_relative_path });
|
|
56
|
+
}
|
|
57
|
+
hasPositionInFile() {
|
|
58
|
+
return this.relativePath !== null && this.line !== null && this.column !== null;
|
|
59
|
+
}
|
|
60
|
+
has_position_in_file() {
|
|
61
|
+
return this.hasPositionInFile();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export class PositionInFile {
|
|
65
|
+
line;
|
|
66
|
+
col;
|
|
67
|
+
constructor(init) {
|
|
68
|
+
this.line = init.line;
|
|
69
|
+
this.col = init.col;
|
|
70
|
+
}
|
|
71
|
+
toLspPosition() {
|
|
72
|
+
return { line: this.line, character: this.col };
|
|
73
|
+
}
|
|
74
|
+
to_lsp_position() {
|
|
75
|
+
return this.toLspPosition();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export class Symbol {
|
|
79
|
+
getBodyStartPositionOrRaise() {
|
|
80
|
+
const position = this.getBodyStartPosition();
|
|
81
|
+
if (!position) {
|
|
82
|
+
throw new Error(`Body start position is not defined for ${this.constructor.name}`);
|
|
83
|
+
}
|
|
84
|
+
return position;
|
|
85
|
+
}
|
|
86
|
+
getBodyEndPositionOrRaise() {
|
|
87
|
+
const position = this.getBodyEndPosition();
|
|
88
|
+
if (!position) {
|
|
89
|
+
throw new Error(`Body end position is not defined for ${this.constructor.name}`);
|
|
90
|
+
}
|
|
91
|
+
return position;
|
|
92
|
+
}
|
|
93
|
+
get_body_start_position() {
|
|
94
|
+
return this.getBodyStartPosition();
|
|
95
|
+
}
|
|
96
|
+
get_body_end_position() {
|
|
97
|
+
return this.getBodyEndPosition();
|
|
98
|
+
}
|
|
99
|
+
get_body_start_position_or_raise() {
|
|
100
|
+
return this.getBodyStartPositionOrRaise();
|
|
101
|
+
}
|
|
102
|
+
get_body_end_position_or_raise() {
|
|
103
|
+
return this.getBodyEndPositionOrRaise();
|
|
104
|
+
}
|
|
105
|
+
is_neighbouring_definition_separated_by_empty_line() {
|
|
106
|
+
return this.isNeighbouringDefinitionSeparatedByEmptyLine();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function normalizeRelativePath(candidate) {
|
|
110
|
+
if (candidate === null || candidate === undefined) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return candidate.replace(/\//g, path.sep);
|
|
114
|
+
}
|
|
115
|
+
function resolveSymbolLocation(raw) {
|
|
116
|
+
if (raw.location && typeof raw.location === 'object') {
|
|
117
|
+
return raw.location;
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
function resolveSelectionRange(raw) {
|
|
122
|
+
if (raw.selectionRange && typeof raw.selectionRange === 'object') {
|
|
123
|
+
return raw.selectionRange;
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
export class LanguageServerSymbol extends Symbol {
|
|
128
|
+
static NAME_PATH_SEPARATOR = '/';
|
|
129
|
+
symbolRoot;
|
|
130
|
+
constructor(symbolRoot) {
|
|
131
|
+
super();
|
|
132
|
+
this.symbolRoot = symbolRoot;
|
|
133
|
+
}
|
|
134
|
+
static matchNamePath(namePath, symbolNamePathParts, substringMatching) {
|
|
135
|
+
if (!namePath) {
|
|
136
|
+
throw new Error('name_path must not be empty');
|
|
137
|
+
}
|
|
138
|
+
if (!symbolNamePathParts || symbolNamePathParts.length === 0) {
|
|
139
|
+
throw new Error('symbol_name_path_parts must not be empty');
|
|
140
|
+
}
|
|
141
|
+
const sep = LanguageServerSymbol.NAME_PATH_SEPARATOR;
|
|
142
|
+
const isAbsolutePattern = namePath.startsWith(sep);
|
|
143
|
+
const patternParts = namePath
|
|
144
|
+
.replace(/^\/*/u, '')
|
|
145
|
+
.replace(/\/*$/u, '')
|
|
146
|
+
.split(sep)
|
|
147
|
+
.filter((part) => part.length > 0);
|
|
148
|
+
if (patternParts.length === 0) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
if (patternParts.length > symbolNamePathParts.length) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (isAbsolutePattern && patternParts.length !== symbolNamePathParts.length) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
const expectedAncestors = patternParts.slice(0, -1);
|
|
158
|
+
const candidateAncestors = symbolNamePathParts.slice(-patternParts.length, -1);
|
|
159
|
+
if (expectedAncestors.length > 0 && expectedAncestors.join('\u0000') !== candidateAncestors.join('\u0000')) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
const needle = patternParts[patternParts.length - 1] ?? '';
|
|
163
|
+
const haystack = symbolNamePathParts[symbolNamePathParts.length - 1] ?? '';
|
|
164
|
+
return substringMatching ? haystack.includes(needle) : haystack === needle;
|
|
165
|
+
}
|
|
166
|
+
get name() {
|
|
167
|
+
return this.symbolRoot.name ?? '';
|
|
168
|
+
}
|
|
169
|
+
get kind() {
|
|
170
|
+
return SymbolKind[this.symbolKind] ?? 'Unknown';
|
|
171
|
+
}
|
|
172
|
+
get symbolKind() {
|
|
173
|
+
const rawKind = this.symbolRoot.kind;
|
|
174
|
+
if (typeof rawKind === 'number' && rawKind in SymbolKind) {
|
|
175
|
+
return rawKind;
|
|
176
|
+
}
|
|
177
|
+
return SymbolKind.Object;
|
|
178
|
+
}
|
|
179
|
+
get relativePath() {
|
|
180
|
+
const location = resolveSymbolLocation(this.symbolRoot);
|
|
181
|
+
if (!location) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return normalizeRelativePath(location.relativePath ?? null);
|
|
185
|
+
}
|
|
186
|
+
get location() {
|
|
187
|
+
return new LanguageServerSymbolLocation({
|
|
188
|
+
relativePath: this.relativePath,
|
|
189
|
+
line: this.line,
|
|
190
|
+
column: this.column
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
get body() {
|
|
194
|
+
const body = this.symbolRoot.body;
|
|
195
|
+
return typeof body === 'string' ? body : undefined;
|
|
196
|
+
}
|
|
197
|
+
get line() {
|
|
198
|
+
const selection = resolveSelectionRange(this.symbolRoot);
|
|
199
|
+
if (selection?.start?.line !== undefined) {
|
|
200
|
+
return selection.start.line;
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
get column() {
|
|
205
|
+
const selection = resolveSelectionRange(this.symbolRoot);
|
|
206
|
+
if (selection?.start?.character !== undefined) {
|
|
207
|
+
return selection.start.character;
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
isNeighbouringDefinitionSeparatedByEmptyLine() {
|
|
212
|
+
return (this.symbolKind === SymbolKind.Function ||
|
|
213
|
+
this.symbolKind === SymbolKind.Method ||
|
|
214
|
+
this.symbolKind === SymbolKind.Class ||
|
|
215
|
+
this.symbolKind === SymbolKind.Interface ||
|
|
216
|
+
this.symbolKind === SymbolKind.Struct);
|
|
217
|
+
}
|
|
218
|
+
getBodyStartPosition() {
|
|
219
|
+
const location = resolveSymbolLocation(this.symbolRoot);
|
|
220
|
+
const start = location?.range?.start;
|
|
221
|
+
if (!start) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
return new PositionInFile({ line: start.line ?? 0, col: start.character ?? 0 });
|
|
225
|
+
}
|
|
226
|
+
getBodyEndPosition() {
|
|
227
|
+
const location = resolveSymbolLocation(this.symbolRoot);
|
|
228
|
+
const end = location?.range?.end;
|
|
229
|
+
if (!end) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
return new PositionInFile({ line: end.line ?? 0, col: end.character ?? 0 });
|
|
233
|
+
}
|
|
234
|
+
getBodyLineNumbers() {
|
|
235
|
+
const range = resolveSymbolLocation(this.symbolRoot)?.range;
|
|
236
|
+
const startLine = range?.start?.line ?? null;
|
|
237
|
+
const endLine = range?.end?.line ?? null;
|
|
238
|
+
return [startLine, endLine];
|
|
239
|
+
}
|
|
240
|
+
getBodyStartPositionOrRaise() {
|
|
241
|
+
return super.getBodyStartPositionOrRaise();
|
|
242
|
+
}
|
|
243
|
+
getBodyEndPositionOrRaise() {
|
|
244
|
+
return super.getBodyEndPositionOrRaise();
|
|
245
|
+
}
|
|
246
|
+
get_name_path() {
|
|
247
|
+
return this.getNamePath();
|
|
248
|
+
}
|
|
249
|
+
getNamePath() {
|
|
250
|
+
return this.getNamePathParts().join(LanguageServerSymbol.NAME_PATH_SEPARATOR);
|
|
251
|
+
}
|
|
252
|
+
getNamePathParts() {
|
|
253
|
+
const ancestors = Array.from(this.iterAncestors(SymbolKind.File)).reverse();
|
|
254
|
+
const ancestorNames = ancestors.map((ancestor) => ancestor.name);
|
|
255
|
+
return [...ancestorNames, this.name];
|
|
256
|
+
}
|
|
257
|
+
get_name_path_parts() {
|
|
258
|
+
return this.getNamePathParts();
|
|
259
|
+
}
|
|
260
|
+
*iterChildren() {
|
|
261
|
+
const children = Array.isArray(this.symbolRoot.children) ? this.symbolRoot.children : [];
|
|
262
|
+
for (const child of children) {
|
|
263
|
+
if (child) {
|
|
264
|
+
yield new LanguageServerSymbol(child);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
iter_children() {
|
|
269
|
+
return this.iterChildren();
|
|
270
|
+
}
|
|
271
|
+
*iterAncestors(upToSymbolKind) {
|
|
272
|
+
const parent = this.getParent();
|
|
273
|
+
if (!parent) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (upToSymbolKind === undefined || parent.symbolKind !== upToSymbolKind) {
|
|
277
|
+
yield parent;
|
|
278
|
+
yield* parent.iterAncestors(upToSymbolKind);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
iter_ancestors(upToSymbolKind) {
|
|
282
|
+
return this.iterAncestors(upToSymbolKind);
|
|
283
|
+
}
|
|
284
|
+
getParent() {
|
|
285
|
+
const parent = this.symbolRoot.parent;
|
|
286
|
+
if (!parent) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
return new LanguageServerSymbol(parent);
|
|
290
|
+
}
|
|
291
|
+
get_parent() {
|
|
292
|
+
return this.getParent();
|
|
293
|
+
}
|
|
294
|
+
find(namePath, options = {}) {
|
|
295
|
+
const { substringMatching = false, includeKinds, excludeKinds } = options;
|
|
296
|
+
const include = includeKinds ? new Set(includeKinds.map((kind) => Number(kind))) : null;
|
|
297
|
+
const exclude = excludeKinds ? new Set(excludeKinds.map((kind) => Number(kind))) : null;
|
|
298
|
+
const result = [];
|
|
299
|
+
const shouldInclude = (symbol) => {
|
|
300
|
+
if (include?.has(symbol.symbolKind) === false) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
if (exclude?.has(symbol.symbolKind)) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
return LanguageServerSymbol.matchNamePath(namePath, symbol.getNamePathParts(), substringMatching);
|
|
307
|
+
};
|
|
308
|
+
const traverse = (symbol) => {
|
|
309
|
+
if (shouldInclude(symbol)) {
|
|
310
|
+
result.push(symbol);
|
|
311
|
+
}
|
|
312
|
+
for (const child of symbol.iterChildren()) {
|
|
313
|
+
traverse(child);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
traverse(this);
|
|
317
|
+
return result;
|
|
318
|
+
}
|
|
319
|
+
find_symbols(namePath, substringMatching = false, includeKinds, excludeKinds) {
|
|
320
|
+
return this.find(namePath, { substringMatching, includeKinds, excludeKinds });
|
|
321
|
+
}
|
|
322
|
+
toDict(options = {}) {
|
|
323
|
+
const { kind = false, location = false, depth = 0, includeBody = false, includeChildrenBody = false, includeRelativePath = true } = options;
|
|
324
|
+
const result = {
|
|
325
|
+
name: this.name,
|
|
326
|
+
name_path: this.getNamePath()
|
|
327
|
+
};
|
|
328
|
+
if (kind) {
|
|
329
|
+
result.kind = this.kind;
|
|
330
|
+
}
|
|
331
|
+
if (location) {
|
|
332
|
+
result.location = this.location.toDict({ includeRelativePath });
|
|
333
|
+
const [startLine, endLine] = this.getBodyLineNumbers();
|
|
334
|
+
result.body_location = { start_line: startLine, end_line: endLine };
|
|
335
|
+
}
|
|
336
|
+
if (includeBody) {
|
|
337
|
+
if (this.body === undefined) {
|
|
338
|
+
logger.warn(`Requested body for symbol ${this.name}, but it is not present. The symbol might have been loaded without include_body.`);
|
|
339
|
+
}
|
|
340
|
+
result.body = this.body ?? null;
|
|
341
|
+
}
|
|
342
|
+
if (depth > 0) {
|
|
343
|
+
result.children = this.collectChildren({
|
|
344
|
+
depth,
|
|
345
|
+
includeBody: includeChildrenBody,
|
|
346
|
+
includeLocation: location,
|
|
347
|
+
includeKind: kind
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
to_dict(options) {
|
|
353
|
+
return this.toDict({
|
|
354
|
+
kind: options?.kind,
|
|
355
|
+
location: options?.location,
|
|
356
|
+
depth: options?.depth,
|
|
357
|
+
includeBody: options?.include_body,
|
|
358
|
+
includeChildrenBody: options?.include_children_body,
|
|
359
|
+
includeRelativePath: options?.include_relative_path
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
collectChildren(options) {
|
|
363
|
+
const { depth, includeBody, includeLocation, includeKind } = options;
|
|
364
|
+
const result = [];
|
|
365
|
+
if (depth <= 0) {
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
for (const child of this.iterChildren()) {
|
|
369
|
+
result.push(child.toDict({
|
|
370
|
+
kind: includeKind,
|
|
371
|
+
location: includeLocation,
|
|
372
|
+
depth: depth - 1,
|
|
373
|
+
includeBody,
|
|
374
|
+
includeChildrenBody: includeBody,
|
|
375
|
+
includeRelativePath: false
|
|
376
|
+
}));
|
|
377
|
+
}
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
export class ReferenceInLanguageServerSymbol {
|
|
382
|
+
symbol;
|
|
383
|
+
line;
|
|
384
|
+
character;
|
|
385
|
+
constructor(init) {
|
|
386
|
+
this.symbol = init.symbol;
|
|
387
|
+
this.line = init.line;
|
|
388
|
+
this.character = init.character;
|
|
389
|
+
}
|
|
390
|
+
static fromLspReference(reference) {
|
|
391
|
+
return new ReferenceInLanguageServerSymbol({
|
|
392
|
+
symbol: new LanguageServerSymbol(reference.symbol),
|
|
393
|
+
line: reference.line,
|
|
394
|
+
character: reference.character
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
get_relative_path() {
|
|
398
|
+
return this.symbol.location.relativePath;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
function toNumberKindSet(values) {
|
|
402
|
+
if (!values || values.length === 0) {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
return new Set(values.map((value) => Number(value)));
|
|
406
|
+
}
|
|
407
|
+
export class LanguageServerSymbolRetriever {
|
|
408
|
+
_langServer;
|
|
409
|
+
agent;
|
|
410
|
+
constructor(langServer, agent = null) {
|
|
411
|
+
this._langServer = langServer;
|
|
412
|
+
this.agent = agent;
|
|
413
|
+
}
|
|
414
|
+
setLanguageServer(langServer) {
|
|
415
|
+
this._langServer = langServer;
|
|
416
|
+
}
|
|
417
|
+
set_language_server(langServer) {
|
|
418
|
+
this.setLanguageServer(langServer);
|
|
419
|
+
}
|
|
420
|
+
getLanguageServer() {
|
|
421
|
+
return this._langServer;
|
|
422
|
+
}
|
|
423
|
+
get_language_server() {
|
|
424
|
+
return this.getLanguageServer();
|
|
425
|
+
}
|
|
426
|
+
findByName(namePath, options = {}) {
|
|
427
|
+
const { includeBody = false, includeKinds, excludeKinds, substringMatching = false, withinRelativePath } = options;
|
|
428
|
+
const symbolRoots = this._langServer.requestFullSymbolTree({
|
|
429
|
+
withinRelativePath: withinRelativePath ?? undefined,
|
|
430
|
+
includeBody
|
|
431
|
+
});
|
|
432
|
+
const includeSet = toNumberKindSet(includeKinds);
|
|
433
|
+
const excludeSet = toNumberKindSet(excludeKinds);
|
|
434
|
+
const matches = [];
|
|
435
|
+
for (const root of symbolRoots) {
|
|
436
|
+
const symbol = new LanguageServerSymbol(root);
|
|
437
|
+
const found = symbol.find(namePath, {
|
|
438
|
+
includeKinds: includeSet ? Array.from(includeSet) : undefined,
|
|
439
|
+
excludeKinds: excludeSet ? Array.from(excludeSet) : undefined,
|
|
440
|
+
substringMatching
|
|
441
|
+
});
|
|
442
|
+
matches.push(...found);
|
|
443
|
+
}
|
|
444
|
+
return matches;
|
|
445
|
+
}
|
|
446
|
+
find_by_name(namePath, includeBody = false, includeKinds, excludeKinds, substringMatching = false, withinRelativePath) {
|
|
447
|
+
return this.findByName(namePath, {
|
|
448
|
+
includeBody,
|
|
449
|
+
includeKinds,
|
|
450
|
+
excludeKinds,
|
|
451
|
+
substringMatching,
|
|
452
|
+
withinRelativePath
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
getDocumentSymbols(relativePath) {
|
|
456
|
+
const result = this._langServer.requestDocumentSymbols(relativePath, { includeBody: false });
|
|
457
|
+
return result.documentSymbols.map((entry) => new LanguageServerSymbol(entry));
|
|
458
|
+
}
|
|
459
|
+
get_document_symbols(relativePath) {
|
|
460
|
+
return this.getDocumentSymbols(relativePath);
|
|
461
|
+
}
|
|
462
|
+
findByLocation(location) {
|
|
463
|
+
if (!location.relativePath) {
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
const result = this._langServer.requestDocumentSymbols(location.relativePath, { includeBody: false });
|
|
467
|
+
for (const symbolDict of result.documentSymbols) {
|
|
468
|
+
const symbol = new LanguageServerSymbol(symbolDict);
|
|
469
|
+
if (symbol.location.relativePath === location.relativePath && symbol.line === location.line) {
|
|
470
|
+
return symbol;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
find_by_location(location) {
|
|
476
|
+
return this.findByLocation(location);
|
|
477
|
+
}
|
|
478
|
+
findReferencingSymbols(namePath, relativeFilePath, options = {}) {
|
|
479
|
+
const { includeBody = false, includeKinds, excludeKinds } = options;
|
|
480
|
+
const matches = this.findByName(namePath, {
|
|
481
|
+
includeBody,
|
|
482
|
+
includeKinds,
|
|
483
|
+
excludeKinds,
|
|
484
|
+
withinRelativePath: relativeFilePath
|
|
485
|
+
});
|
|
486
|
+
if (matches.length === 0) {
|
|
487
|
+
return [];
|
|
488
|
+
}
|
|
489
|
+
const target = matches[0];
|
|
490
|
+
const references = this._langServer.requestReferencingSymbols({
|
|
491
|
+
relativeFilePath,
|
|
492
|
+
line: target.line ?? 0,
|
|
493
|
+
column: target.column ?? 0,
|
|
494
|
+
includeBody,
|
|
495
|
+
includeImports: false,
|
|
496
|
+
includeSelf: false,
|
|
497
|
+
includeFileSymbols: true
|
|
498
|
+
});
|
|
499
|
+
const includeSet = toNumberKindSet(includeKinds);
|
|
500
|
+
const excludeSet = toNumberKindSet(excludeKinds);
|
|
501
|
+
return references
|
|
502
|
+
.filter((reference) => {
|
|
503
|
+
const symbol = new LanguageServerSymbol(reference.symbol);
|
|
504
|
+
if (includeSet?.has(symbol.symbolKind) === false) {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
if (excludeSet?.has(symbol.symbolKind)) {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
return true;
|
|
511
|
+
})
|
|
512
|
+
.map((reference) => ReferenceInLanguageServerSymbol.fromLspReference(reference));
|
|
513
|
+
}
|
|
514
|
+
find_referencing_symbols(namePath, relativeFilePath, includeBody = false, includeKinds, excludeKinds) {
|
|
515
|
+
return this.findReferencingSymbols(namePath, relativeFilePath, {
|
|
516
|
+
includeBody,
|
|
517
|
+
includeKinds,
|
|
518
|
+
excludeKinds
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
findReferencingSymbolsByLocation(location, options = {}) {
|
|
522
|
+
if (!location.hasPositionInFile()) {
|
|
523
|
+
throw new Error('Symbol location does not contain a valid position in a file.');
|
|
524
|
+
}
|
|
525
|
+
const references = this._langServer.requestReferencingSymbols({
|
|
526
|
+
relativeFilePath: location.relativePath ?? '',
|
|
527
|
+
line: location.line ?? 0,
|
|
528
|
+
column: location.column ?? 0,
|
|
529
|
+
includeBody: options.includeBody ?? false,
|
|
530
|
+
includeImports: false,
|
|
531
|
+
includeSelf: false,
|
|
532
|
+
includeFileSymbols: true
|
|
533
|
+
});
|
|
534
|
+
const includeSet = toNumberKindSet(options.includeKinds);
|
|
535
|
+
const excludeSet = toNumberKindSet(options.excludeKinds);
|
|
536
|
+
return references
|
|
537
|
+
.filter((reference) => {
|
|
538
|
+
const symbol = new LanguageServerSymbol(reference.symbol);
|
|
539
|
+
if (includeSet?.has(symbol.symbolKind) === false) {
|
|
540
|
+
return false;
|
|
541
|
+
}
|
|
542
|
+
if (excludeSet?.has(symbol.symbolKind)) {
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
return true;
|
|
546
|
+
})
|
|
547
|
+
.map((reference) => ReferenceInLanguageServerSymbol.fromLspReference(reference));
|
|
548
|
+
}
|
|
549
|
+
find_referencing_symbols_by_location(location, includeBody = false, includeKinds, excludeKinds) {
|
|
550
|
+
return this.findReferencingSymbolsByLocation(location, {
|
|
551
|
+
includeBody,
|
|
552
|
+
includeKinds,
|
|
553
|
+
excludeKinds
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
static symbolOverviewFromSymbol(symbol) {
|
|
557
|
+
return {
|
|
558
|
+
name_path: symbol.getNamePath(),
|
|
559
|
+
kind: Number(symbol.symbolKind)
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
getSymbolOverview(relativePath) {
|
|
563
|
+
const overview = this._langServer.requestOverview(relativePath);
|
|
564
|
+
const result = {};
|
|
565
|
+
for (const filePath of Object.keys(overview)) {
|
|
566
|
+
const symbols = overview[filePath] ?? [];
|
|
567
|
+
const mappedSymbols = symbols.map((symbol) => LanguageServerSymbolRetriever.symbolOverviewFromSymbol(new LanguageServerSymbol(symbol)));
|
|
568
|
+
result[filePath] = mappedSymbols;
|
|
569
|
+
}
|
|
570
|
+
return result;
|
|
571
|
+
}
|
|
572
|
+
get_symbol_overview(relativePath) {
|
|
573
|
+
return this.getSymbolOverview(relativePath);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
export class JetBrainsSymbol extends Symbol {
|
|
577
|
+
data;
|
|
578
|
+
constructor(symbolDict) {
|
|
579
|
+
super();
|
|
580
|
+
this.data = { ...symbolDict };
|
|
581
|
+
}
|
|
582
|
+
ensureTextRange() {
|
|
583
|
+
const textRange = this.data.text_range;
|
|
584
|
+
if (!textRange || typeof textRange !== 'object') {
|
|
585
|
+
return null;
|
|
586
|
+
}
|
|
587
|
+
const startPos = textRange.start_pos;
|
|
588
|
+
const endPos = textRange.end_pos;
|
|
589
|
+
if (!startPos || !endPos) {
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
return { start_pos: startPos, end_pos: endPos };
|
|
593
|
+
}
|
|
594
|
+
getBodyStartPosition() {
|
|
595
|
+
const range = this.ensureTextRange();
|
|
596
|
+
if (!range) {
|
|
597
|
+
return null;
|
|
598
|
+
}
|
|
599
|
+
return new PositionInFile({ line: Number(range.start_pos.line ?? 0), col: Number(range.start_pos.col ?? 0) });
|
|
600
|
+
}
|
|
601
|
+
getBodyEndPosition() {
|
|
602
|
+
const range = this.ensureTextRange();
|
|
603
|
+
if (!range) {
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
return new PositionInFile({ line: Number(range.end_pos.line ?? 0), col: Number(range.end_pos.col ?? 0) });
|
|
607
|
+
}
|
|
608
|
+
isNeighbouringDefinitionSeparatedByEmptyLine() {
|
|
609
|
+
return true;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
export class JetBrainsCodeEditorNotAvailableError extends Error {
|
|
613
|
+
constructor() {
|
|
614
|
+
super('JetBrains IDE integration is not available in the current TypeScript port.');
|
|
615
|
+
}
|
|
616
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export declare enum LineType {
|
|
2
|
+
MATCH = "match",
|
|
3
|
+
BEFORE_MATCH = "prefix",
|
|
4
|
+
AFTER_MATCH = "postfix"
|
|
5
|
+
}
|
|
6
|
+
export declare class TextLine {
|
|
7
|
+
readonly lineNumber: number;
|
|
8
|
+
readonly lineContent: string;
|
|
9
|
+
readonly matchType: LineType;
|
|
10
|
+
constructor(options: {
|
|
11
|
+
lineNumber: number;
|
|
12
|
+
lineContent: string;
|
|
13
|
+
matchType: LineType;
|
|
14
|
+
});
|
|
15
|
+
private getDisplayPrefix;
|
|
16
|
+
formatLine(includeLineNumbers?: boolean): string;
|
|
17
|
+
}
|
|
18
|
+
export declare class MatchedConsecutiveLines {
|
|
19
|
+
readonly lines: TextLine[];
|
|
20
|
+
readonly sourceFilePath?: string;
|
|
21
|
+
readonly linesBeforeMatched: TextLine[];
|
|
22
|
+
readonly matchedLines: TextLine[];
|
|
23
|
+
readonly linesAfterMatched: TextLine[];
|
|
24
|
+
constructor(options: {
|
|
25
|
+
lines: TextLine[];
|
|
26
|
+
sourceFilePath?: string;
|
|
27
|
+
});
|
|
28
|
+
get startLine(): number;
|
|
29
|
+
get endLine(): number;
|
|
30
|
+
get numMatchedLines(): number;
|
|
31
|
+
toDisplayString(includeLineNumbers?: boolean): string;
|
|
32
|
+
static fromFileContents(options: {
|
|
33
|
+
fileContents: string;
|
|
34
|
+
line: number;
|
|
35
|
+
contextLinesBefore?: number;
|
|
36
|
+
contextLinesAfter?: number;
|
|
37
|
+
sourceFilePath?: string;
|
|
38
|
+
}): MatchedConsecutiveLines;
|
|
39
|
+
}
|
|
40
|
+
interface SearchTextOptions {
|
|
41
|
+
contextLinesBefore?: number;
|
|
42
|
+
contextLinesAfter?: number;
|
|
43
|
+
}
|
|
44
|
+
interface SearchFilesOptions extends SearchTextOptions {
|
|
45
|
+
rootPath?: string;
|
|
46
|
+
fileReader?: (absolutePath: string) => string;
|
|
47
|
+
pathsIncludeGlob?: string | null;
|
|
48
|
+
pathsExcludeGlob?: string | null;
|
|
49
|
+
}
|
|
50
|
+
export declare function searchFiles(relativeFilePaths: string[], pattern: string, options?: SearchFilesOptions): MatchedConsecutiveLines[];
|
|
51
|
+
export {};
|