Skip to main content

zoi_cli/cmd/package/
init_lsp.rs

1//! Initialization of LSP support for package development.
2
3use anyhow::Result;
4use clap::Parser;
5use colored::Colorize;
6
7/// Command to initialize LSP support in a workspace.
8#[derive(Parser, Debug)]
9pub struct InitLspCommand {
10    /// Path where the LSP configuration should be initialized
11    #[arg(default_value = ".")]
12    pub path: std::path::PathBuf
13}
14
15/// Runs the LSP initialization command.
16///
17/// This setup creates necessary configuration files (like `.luarc.json`) and
18/// downloads type definitions to enable better development experience in
19/// LSP-supported editors.
20///
21/// # Errors
22///
23/// Returns an error if the LSP workspace setup fails.
24pub fn run(args: &InitLspCommand) -> Result<()> {
25    println!(
26        "{} Initializing LSP support in {}...",
27        "::".bold().blue(),
28        args.path.display()
29    );
30
31    crate::pkg::package::init_lsp::setup_lsp_workspace(&args.path)?;
32
33    println!(
34        "{} LSP support initialized. Created .luarc.json and type definitions.",
35        "::".bold().green()
36    );
37    println!(
38        "{} Use 'lua-language-server' for rich autocomplete and documentation.",
39        "Note:".yellow()
40    );
41
42    Ok(())
43}