|
1 | | -""" |
2 | | -This script is the dedicated entry point for the Codeflash Language Server. |
| 1 | +"""This script is the dedicated entry point for the Codeflash Language Server. |
3 | 2 | It initializes the server and redirects its logs to stderr so that the |
4 | 3 | VS Code client can display them in the output channel. |
5 | 4 |
|
6 | 5 | This script is run by the VS Code extension and is not intended to be |
7 | 6 | executed directly by users. |
8 | 7 | """ |
| 8 | + |
9 | 9 | import logging |
10 | 10 | import sys |
11 | | -import os |
| 11 | + |
12 | 12 | from codeflash.lsp.beta import server |
13 | 13 |
|
| 14 | + |
14 | 15 | # Configure logging to stderr for VS Code output channel |
15 | 16 | def setup_logging(): |
16 | 17 | # Clear any existing handlers to prevent conflicts |
17 | 18 | root_logger = logging.getLogger() |
18 | 19 | root_logger.handlers.clear() |
19 | | - |
| 20 | + |
20 | 21 | # Set up stderr handler for VS Code output channel with [LSP-Server] prefix |
21 | 22 | handler = logging.StreamHandler(sys.stderr) |
22 | 23 | handler.setFormatter(logging.Formatter("[LSP-Server] %(asctime)s [%(levelname)s]: %(message)s")) |
23 | | - |
| 24 | + |
24 | 25 | # Configure root logger |
25 | 26 | root_logger.addHandler(handler) |
26 | 27 | root_logger.setLevel(logging.INFO) |
27 | | - |
| 28 | + |
28 | 29 | # Also configure the pygls logger specifically |
29 | | - pygls_logger = logging.getLogger('pygls') |
| 30 | + pygls_logger = logging.getLogger("pygls") |
30 | 31 | pygls_logger.setLevel(logging.INFO) |
31 | | - |
| 32 | + |
32 | 33 | return root_logger |
33 | 34 |
|
34 | | -# Set up logging |
35 | | -log = setup_logging() |
36 | 35 |
|
37 | | -# Silence the console module to prevent stdout pollution |
38 | | -from codeflash.cli_cmds.console import console |
39 | | -console.quiet = True |
| 36 | +if __name__ == "__main__": |
| 37 | + # Set up logging |
| 38 | + log = setup_logging() |
| 39 | + log.info("Starting Codeflash Language Server...") |
| 40 | + |
| 41 | + # Silence the console module to prevent stdout pollution |
| 42 | + from codeflash.cli_cmds.console import console |
| 43 | + |
| 44 | + console.quiet = True |
| 45 | + # console.enable() |
40 | 46 |
|
41 | | -log.info("Starting Codeflash Language Server...") |
42 | | -server.start_io() |
| 47 | + # Start the language server |
| 48 | + server.start_io() |
0 commit comments