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

fix hanging on windows #130

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

fix hanging on windows #130

wants to merge 5 commits into from

Conversation

phcreery
Copy link

@phcreery phcreery commented Sep 28, 2024

fix #128
vfmt on large files fills the stdout output buffer but v-analyzer does not read the buffer until vfmt exits.

// test_file := 'file:///c%3A/Users/phcre/Documents/v/imageeditor/testing/proc.v'
dump(test_file)

src := os.read_file(test_file) or { panic('Cannot read file') }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.read_file handles relative and absolute paths, like the ones returned by os.real_path .

Comment on lines 17 to 32
mut fmt_proc := ls.launch_tool('fmt', temp_formatting_file_path)!
loglib.info('Formatting file: ${temp_formatting_file_path} ${file.uri}')

mut fmt_proc := ls.launch_tool('fmt', os.norm_path(temp_formatting_file_path)) or { return [] }
defer {
fmt_proc.close()
}
fmt_proc.run()

// read entire output until EOF
mut output := fmt_proc.stdout_slurp()
fmt_proc.wait()

if fmt_proc.code != 0 {
loglib.info('Formatting finished with code: ${fmt_proc.code} and status ${fmt_proc.status}')

$if windows {
output = output.replace('\r\r', '\r')
}

if (fmt_proc.code != 0) && (fmt_proc.status == .exited) {
errors := fmt_proc.stderr_slurp().trim_space()
ls.client.show_message(errors, .info)
return error('Formatting failed: ${errors}')
// return []
}

mut output := fmt_proc.stdout_slurp()
$if windows {
output = output.replace('\r\r', '\r')
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is complicated for no reason. Just res := os.execute('v fmt file.v') and then using res.exit_code and res.output should be enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the goal avoiding reading from stderr?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not write this originally but I believe that is the case. the stdout gets sent to the IDE and is used to replace the text in the buffer. the stderr, if caught, gets sent to the IDE as a warning notification/highlighting. I do think os.execute would work but it is essentially the same thing

@phcreery phcreery marked this pull request as ready for review October 2, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v-analyzer hang or closes on windows
2 participants