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

Merged
merged 8 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 16 additions & 6 deletions src/server/features_formatting.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module server
import lsp
import os
import server.tform
import loglib

const temp_formatting_file_path = os.join_path(os.temp_dir(), 'v-analyzer-formatting-temp.v')

Expand All @@ -14,22 +15,31 @@ pub fn (mut ls LanguageServer) formatting(params lsp.DocumentFormattingParams) !
return error('Cannot write temp file for formatting: ${err}')
}

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')
}
spytheman marked this conversation as resolved.
Show resolved Hide resolved

return [
lsp.TextEdit{
Expand Down
45 changes: 45 additions & 0 deletions src/server/features_formatting_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module server

import lsp
import os
import analyzer
import analyzer.psi
import analyzer.parser




fn test_large_file() {


test_file := os.norm_path(@VMODROOT + '/src/server/general.v')
phcreery marked this conversation as resolved.
Show resolved Hide resolved
// test_file := os.norm_path(@VEXEROOT + '/vlib/os/process_windows.c.v')
// 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 .

// dump(src)

uri := lsp.document_uri_from_path(test_file)
res := parser.parse_code(src)
psi_file := psi.new_psi_file(uri.path(), res.tree, res.source_text)


mut ls := LanguageServer.new(analyzer.IndexingManager.new())
ls.opened_files[uri] = analyzer.OpenedFile{
uri: uri
version: 0
psi_file: psi_file
}

params := lsp.DocumentFormattingParams{
text_document: lsp.TextDocumentIdentifier{
uri: uri
}
}

text_edit_result := ls.formatting(params) or { panic('Cannot format file') }
dump(text_edit_result)
assert text_edit_result.len == 1

}
Loading