diff --git a/handlers.v b/handlers.v index 792cc16f..da7db159 100644 --- a/handlers.v +++ b/handlers.v @@ -30,9 +30,12 @@ fn (mut app App) operation_at_pos(method Method, request Request) Response { } line_info := match method { - .completion, .hover { + .completion { '${line_nr}:${col}' } + .hover { + '${line_nr}:hv^${col}' + } .signature_help { '${line_nr}:fn^${col}' } diff --git a/interop.v b/interop.v index b9318d99..eb22c053 100644 --- a/interop.v +++ b/interop.v @@ -353,18 +353,19 @@ fn (mut app App) run_v_line_info(method Method, path string, line_info string) R result = json.decode(SignatureHelp, x.output) or { SignatureHelp{} } } .hover { - result_tmp := json.decode(JsonVarAC, x.output) or { JsonVarAC{} } + // Decode the Hover JSON emitted by the compiler's hv^ mode. + hover_result := json.decode(Hover, x.output) or { Hover{} } // Extract vdoc comment via cross-file search as a fallback when the // compiler does not provide documentation. mut doc := '' file_content := app.open_files[path] or { app.text } file_lines := file_content.split_into_lines() - // line_info format for hover is "line:col" (1-based line, 0-based col) + // line_info format for hover is "${line_nr}:hv^${col}" info_parts := line_info.split(':') mut cursor_symbol := '' if info_parts.len >= 2 { cursor_line := info_parts[0].int() - 1 - cursor_col := info_parts[1].int() + cursor_col := info_parts[1].all_after('hv^').int() if cursor_line >= 0 && cursor_line < file_lines.len { cursor_symbol = get_word_at_col(file_lines[cursor_line], cursor_col) if cursor_symbol != '' { @@ -373,36 +374,20 @@ fn (mut app App) run_v_line_info(method Method, path string, line_info string) R } } } - if result_tmp.details.len > 0 { - detail := result_tmp.details[0] - // When the compiler returned a named symbol (e.g. hovering over the `fn` - // keyword resolves to the function's label), re-run the doc search using - // the compiler's label so we pick up the correct vdoc comment. - if doc == '' && detail.label != '' && detail.label != cursor_symbol { - doc = app.find_doc_comment_for_symbol(detail.label, file_lines, path) - } - // Prefer compiler-provided documentation over our extracted vdoc - if detail.documentation != '' { - doc = detail.documentation - } - // Use the full declaration from the compiler when available; - // fall back to detail (return type) if declaration is absent. - sig := if detail.declaration != '' { detail.declaration } else { detail.detail } - mut content := if sig != '' { '```v\n${sig}\n```' } else { '' } - if doc != '' { - if content != '' { - content += '\n\n' - } - content += doc + if hover_result.contents.value != '' { + mut value := hover_result.contents.value + // Augment with doc comment if the compiler didn't include one + if doc != '' && !value.contains(doc) { + value += '\n\n' + doc } result = Hover{ contents: MarkupContent{ kind: 'markdown' - value: content + value: value } } } else if doc != '' { - // Compiler returned no type info but we found a vdoc comment + // Compiler returned no info but we found a vdoc comment result = Hover{ contents: MarkupContent{ kind: 'markdown'