11import argparse
22import asyncio
3+ import logging
34import os
45import sys
56import time
1819from vectorcode .cli_utils import (
1920 CliAction ,
2021 Config ,
22+ config_logging ,
2123 find_project_root ,
2224 load_config_file ,
2325 parse_cli_args ,
2830
2931cached_project_configs : dict [str , Config ] = {}
3032DEFAULT_PROJECT_ROOT : str | None = None
33+ logger = logging .getLogger (__name__ )
3134
3235
3336async def make_caches (project_root : str ):
@@ -67,7 +70,9 @@ def get_arg_parser():
6770async def execute_command (ls : LanguageServer , args : list [str ]):
6871 global DEFAULT_PROJECT_ROOT
6972 start_time = time .time ()
73+ logger .info ("Received command arguments: %s" , args )
7074 parsed_args = await parse_cli_args (args )
75+ logger .info ("Parsed command arguments: %s" , parsed_args )
7176 if parsed_args .action not in {CliAction .query , CliAction .ls }:
7277 print (
7378 f"Unsupported vectorcode subcommand: { str (parsed_args .action )} " ,
@@ -77,7 +82,9 @@ async def execute_command(ls: LanguageServer, args: list[str]):
7782 if parsed_args .project_root is None :
7883 if DEFAULT_PROJECT_ROOT is not None :
7984 parsed_args .project_root = DEFAULT_PROJECT_ROOT
85+ logger .warning ("Using DEFAULT_PROJECT_ROOT: %s" , DEFAULT_PROJECT_ROOT )
8086 elif DEFAULT_PROJECT_ROOT is None :
87+ logger .warning ("Updating DEFAULT_PROJECT_ROOT to %s" , parsed_args .project_root )
8188 DEFAULT_PROJECT_ROOT = str (parsed_args .project_root )
8289
8390 if parsed_args .project_root is not None :
@@ -97,6 +104,7 @@ async def execute_command(ls: LanguageServer, args: list[str]):
97104 final_configs = parsed_args
98105 client = await get_client (parsed_args )
99106 collection = None
107+ logger .info ("Merged final configs: %s" , final_configs )
100108 progress_token = str (uuid .uuid4 ())
101109
102110 await ls .progress .create_async (progress_token )
@@ -118,12 +126,12 @@ async def execute_command(ls: LanguageServer, args: list[str]):
118126 await build_query_results (collection , final_configs )
119127 )
120128 finally :
129+ log_message = f"Retrieved { len (final_results )} result{ 's' if len (final_results ) > 1 else '' } in { round (time .time () - start_time , 2 )} s."
121130 ls .progress .end (
122131 progress_token ,
123- types .WorkDoneProgressEnd (
124- message = f"Retrieved { len (final_results )} result{ 's' if len (final_results ) > 1 else '' } in { round (time .time () - start_time , 2 )} s."
125- ),
132+ types .WorkDoneProgressEnd (message = log_message ),
126133 )
134+ logger .info (log_message )
127135 return final_results
128136 case CliAction .ls :
129137 ls .progress .begin (
@@ -141,6 +149,7 @@ async def execute_command(ls: LanguageServer, args: list[str]):
141149 progress_token ,
142150 types .WorkDoneProgressEnd (message = "List retrieved." ),
143151 )
152+ logger .info (f"Retrieved { len (projects )} project(s)." )
144153 return projects
145154
146155
@@ -158,12 +167,19 @@ async def lsp_start() -> int:
158167 else :
159168 DEFAULT_PROJECT_ROOT = os .path .abspath (args .project_root )
160169
170+ if DEFAULT_PROJECT_ROOT is None :
171+ logger .warning ("DEFAULT_PROJECT_ROOT is empty." )
172+ else :
173+ logger .info (f"{ DEFAULT_PROJECT_ROOT = } " )
174+
175+ logger .info ("Parsed LSP server CLI arguments: %s" , args )
161176 await asyncio .to_thread (server .start_io )
162177
163178 return 0
164179
165180
166181def main (): # pragma: nocover
182+ config_logging ("vectorcode-lsp-server" )
167183 asyncio .run (lsp_start ())
168184
169185
0 commit comments