Skip to content

Commit 6863fd8

Browse files
committed
fix(cli): make sure lsp progress is always ended
1 parent 054d1f2 commit 6863fd8

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

src/vectorcode/lsp_main.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,28 @@ async def execute_command(ls: LanguageServer, args: list[str]):
107107
),
108108
)
109109
final_results = []
110-
for path in await get_query_result_files(
111-
collection=collection,
112-
configs=final_configs,
113-
):
114-
if os.path.isfile(path):
115-
with open(path) as fin:
116-
output_path = path
117-
if not final_configs.use_absolute_path:
118-
output_path = os.path.relpath(
119-
path, final_configs.project_root
110+
try:
111+
for path in await get_query_result_files(
112+
collection=collection,
113+
configs=final_configs,
114+
):
115+
if os.path.isfile(path):
116+
with open(path) as fin:
117+
output_path = path
118+
if not final_configs.use_absolute_path:
119+
output_path = os.path.relpath(
120+
path, final_configs.project_root
121+
)
122+
final_results.append(
123+
{"path": output_path, "document": fin.read()}
120124
)
121-
final_results.append(
122-
{"path": output_path, "document": fin.read()}
123-
)
124-
ls.progress.end(
125-
progress_token,
126-
types.WorkDoneProgressEnd(
127-
message=f"Retrieved {len(final_results)} result{'s' if len(final_results) > 1 else ''} in {round(time.time() - start_time, 2)}s."
128-
),
129-
)
125+
finally:
126+
ls.progress.end(
127+
progress_token,
128+
types.WorkDoneProgressEnd(
129+
message=f"Retrieved {len(final_results)} result{'s' if len(final_results) > 1 else ''} in {round(time.time() - start_time, 2)}s."
130+
),
131+
)
130132
return final_results
131133
case CliAction.ls:
132134
ls.progress.begin(
@@ -136,12 +138,14 @@ async def execute_command(ls: LanguageServer, args: list[str]):
136138
message="Looking for other projects indexed by VectorCode",
137139
),
138140
)
139-
projects: list[dict] = await get_collection_list(client)
140-
141-
ls.progress.end(
142-
progress_token,
143-
types.WorkDoneProgressEnd(message="List retrieved."),
144-
)
141+
projects: list[dict] = []
142+
try:
143+
projects.extend(await get_collection_list(client))
144+
finally:
145+
ls.progress.end(
146+
progress_token,
147+
types.WorkDoneProgressEnd(message="List retrieved."),
148+
)
145149
return projects
146150

147151

0 commit comments

Comments
 (0)