Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analyzer: improve setup, extend client and log messages #100

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 38 additions & 27 deletions src/server/general.v
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,22 @@ pub fn (mut ls LanguageServer) initialize(params lsp.InitializeParams, mut wr Re

pub fn (mut ls LanguageServer) initialized(mut wr ResponseWriter) {
loglib.info('-------- New session -------- ')
ls.client.send_server_status(health: 'ok')
if ls.paths.vexe == '' || ls.paths.vlib_root == '' {
ls.client.send_server_status(health: 'error', quiescent: true)
return
} else {
ls.client.send_server_status(health: 'ok')
}

mut work := ls.progress.start('Indexing:', 'roots...', '')

// Used in tests to avoid indexing the standard library
need_index_stdlib := 'no-stdlib' !in ls.initialization_options

if need_index_stdlib {
if ls.paths.vmodules_root != '' {
ls.indexing_mng.indexer.add_indexing_root(ls.paths.vmodules_root, .modules,
ls.paths.cache_dir)
}
if ls.paths.vlib_root != '' {
ls.indexing_mng.indexer.add_indexing_root(ls.paths.vlib_root, .standard_library,
ls.paths.cache_dir)
}
ls.indexing_mng.indexer.add_indexing_root(ls.paths.vmodules_root, .modules, ls.paths.cache_dir)
ls.indexing_mng.indexer.add_indexing_root(ls.paths.vlib_root, .standard_library,
ls.paths.cache_dir)
}

if stubs_root := ls.stubs_root() {
Expand Down Expand Up @@ -146,13 +146,7 @@ pub fn (mut ls LanguageServer) initialized(mut wr ResponseWriter) {

work.end('Indexing finished')

if ls.paths.vlib_root != '' {
ls.client.send_server_status(health: 'ok', quiescent: true)
} else {
msg := 'Cannot find V standard library!
Please, set `custom_vroot` in local or global config.'
ls.client.send_server_status(health: 'error', message: msg, quiescent: true)
}
ls.client.send_server_status(health: 'ok', quiescent: true)
}

fn (mut ls LanguageServer) setup() {
Expand All @@ -164,7 +158,7 @@ fn (mut ls LanguageServer) setup() {
ls.client.log_message('No config found', .warning)
loglib.warn('No config found')
ls.setup_toolchain()
ls.setup_vpaths() or { loglib.error(err.msg()) }
ls.setup_vpaths()
return
}

Expand Down Expand Up @@ -233,7 +227,7 @@ fn (mut ls LanguageServer) setup() {
ls.setup_cache_dir()
}

ls.setup_vpaths() or { loglib.error(err.msg()) }
ls.setup_vpaths()
}

fn (mut ls LanguageServer) setup_cache_dir() {
Expand Down Expand Up @@ -301,21 +295,38 @@ Global config path: ${config.analyzer_configs_path}/${config.analyzer_config_nam
}
}

fn (mut ls LanguageServer) setup_vpaths() ! {
fn (mut ls LanguageServer) setup_vpaths() {
// Prior call of `ls.setup_toolchain()` ensures `ls.paths.vroot` is set.
vexe_path := os.join_path(ls.paths.vroot, $if windows { 'v.exe' } $else { 'v' })
if !os.is_file(vexe_path) {
msg := 'Failed to find V compiler!'
ls.client.log_message(msg, .error)
loglib.error(msg)
} else {
ls.paths.vexe = vexe_path
ls.reporter.compiler_path = vexe_path
}

vlib_path := os.join_path(ls.paths.vroot, 'vlib')
if !os.is_dir(vlib_path) {
return error('Failed to find standard library path')
msg := 'Failed to find V standard library.'
ls.client.log_message(msg, .error)
loglib.error(msg)
} else {
ls.paths.vlib_root = vlib_path
}
ls.paths.vlib_root = vlib_path

vmodules_root := os.vmodules_dir()
if !os.is_dir(vmodules_root) {
return error('Failed to find vmodules path')
msg := 'Failed to find vmodules path.'
ls.client.log_message(msg, .error)
loglib.error(msg)
} else {
ls.paths.vmodules_root = vmodules_root
msg := 'Using "${vmodules_root}" as vmodules root.'
ls.client.log_message(msg, .info)
loglib.info(msg)
}
ls.paths.vmodules_root = vmodules_root
ls.client.log_message('Using "${ls.paths.vmodules_root}" as vmodules root', .info)
loglib.info('Using "${ls.paths.vmodules_root}" as vmodules root')
ls.paths.vexe = os.join_path(ls.paths.vroot, $if windows { 'v.exe' } $else { 'v' })
ls.reporter.compiler_path = ls.paths.vexe
}

fn (mut ls LanguageServer) setup_config_dir() {
Expand Down
2 changes: 1 addition & 1 deletion src/server/setup_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn test_setup_custom_vpaths() {
println(log_out.trim_space())
assert log_out.contains('Find custom VROOT path')
assert log_out.contains('Using "${custom_root}" as toolchain')
assert log_out.contains('Failed to find standard library path')
assert log_out.contains('Failed to find V standard library')

// Test custom_vroot with existing toolchain =================================
cfg_toml = "custom_vroot = '${server.default_vroot}'"
Expand Down