Skip to content
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
1 change: 1 addition & 0 deletions handlers.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2025 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
module main

fn (mut app App) operation_at_pos(method Method, request Request) Response {
line_nr := request.params.position.line + 1
Expand Down
51 changes: 47 additions & 4 deletions interop.v
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
// Copyright (c) 2025 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
module main

import json
import os
import time

fn uri_to_path(uri string) string {
mut path := uri
// Remove file:// or file:/// prefix
if path.starts_with('file:///') || path.starts_with('file://') {
path = path[7..]
}
if path.len > 2 && path[0] == `/` && path[2] == `:` {
path = path[1..]
}
return path
}

fn (mut app App) run_v_check(path string, text string) []JsonError {
tmppath := os.join_path(os.temp_dir(), os.file_name(path))
log('WRITING FILE ${time.now()} ${path}')
Expand All @@ -25,13 +39,42 @@ fn (mut app App) run_v_check(path string, text string) []JsonError {
}

fn (mut app App) run_v_line_info(method Method, path string, line_info string) ResponseResult {
tmppath := os.join_path(os.temp_dir(), os.file_name(path))
log('WRITING FILE ${time.now()} ${path}')
os.write_file(tmppath, app.text) or { panic(err) }
// Convert URI to local file path
real_path := uri_to_path(path)
log('Real path: ${real_path}')
log('Method: ${method}')

// Go to defintion on zed requires the real path
mut file_to_check := real_path
mut working_dir := os.dir(real_path)
tmppath := os.join_path(os.temp_dir(), os.file_name(real_path))
if method == .definition {
log('WRITING FILE ${time.now()} to real path ${real_path}')
os.write_file(real_path, app.text) or {
log('Failed to write to real path: ${err}')
os.write_file(tmppath, app.text) or { panic(err) }
file_to_check = tmppath
working_dir = os.temp_dir()
}
} else {
log('WRITING FILE ${time.now()} to temp path ${tmppath}')
os.write_file(tmppath, app.text) or { panic(err) }
file_to_check = tmppath
working_dir = os.temp_dir()
}

log('running v.exe line info!')
cmd := 'v -w -check -json-errors -nocolor -vls-mode -line-info "${tmppath}:${line_info}" ${tmppath}'
log('file_to_check=${file_to_check}')
log('working_dir=${working_dir}')
cmd := 'v -w -check -json-errors -nocolor -vls-mode -line-info "${file_to_check}:${line_info}" ${file_to_check}'
log('cmd=${cmd}')

// Change to the working directory to preserve project context
original_dir := os.getwd()
os.chdir(working_dir) or { log('Failed to change to working dir: ${err}') }
x := os.execute(cmd)
os.chdir(original_dir) or {}

log('RUN RES ${x}')
mut result := ResponseResult{}
match method {
Expand Down
2 changes: 2 additions & 0 deletions lsp.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2025 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
module main

struct Request {
id int
method string
Expand Down
2 changes: 2 additions & 0 deletions main.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2025 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
module main

import json
import os
import v.pref
Expand Down