-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12dd6e8
commit b9a233b
Showing
10 changed files
with
227 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -880,3 +880,4 @@ pub fn (f &File) tell() !i64 { | |
} | ||
return pos | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved. | ||
// Use of this source code is governed by an MIT license that can be found in the LICENSE file. | ||
module checker | ||
|
||
import strings | ||
import v.ast | ||
import os | ||
|
||
fn (mut c Checker) ident_autocomplete(node ast.Ident) { | ||
// Mini LS hack (v -line-info "a.v:16") | ||
println( | ||
'checker.ident() info.line_nr=${c.pref.linfo.line_nr} node.line_nr=${node.pos.line_nr} ' + | ||
' pwd="${os.getwd()}" file="${c.file.path}", ' + | ||
' pref.linfo.path="${c.pref.linfo.path}" node.name="${node.name}" expr="${c.pref.linfo.expr}"') | ||
// Make sure this ident is on the same line as requeste, in the same file, and has the same name | ||
same_line := node.pos.line_nr in [c.pref.linfo.line_nr - 1, c.pref.linfo.line_nr + 1, c.pref.linfo.line_nr] | ||
if !same_line { | ||
return | ||
} | ||
same_name := c.pref.linfo.expr == node.name | ||
if !same_name { | ||
return | ||
} | ||
abs_path := os.join_path(os.getwd(), c.file.path) | ||
if c.pref.linfo.path !in [c.file.path, abs_path] { | ||
return | ||
} | ||
mut sb := strings.new_builder(10) | ||
if node.kind == .unresolved { | ||
// println(node) | ||
eprintln('unresolved type, maybe "${node.name}" was not defined. otherwise this is a bug, should never happen; please report') | ||
exit(1) | ||
} | ||
sym := c.table.sym(c.unwrap_generic(node.obj.typ)) | ||
// sb.writeln('VAR ${node.name}:${sym.name} ${node.pos.line_nr}') | ||
nt := '${node.name}:${sym.name}' | ||
if !c.pref.linfo.vars_printed[nt] { // avoid dups | ||
sb.writeln('===') | ||
sb.writeln('VAR ${nt}') //${node.name}:${sym.name}') | ||
/// print_backtrace() | ||
/* | ||
if sym.kind == .alias { | ||
parent_sym := c.table.sym(sym.parent_type) | ||
} | ||
*/ | ||
|
||
mut fields := []ACFieldMethod{cap: 10} | ||
if sym.kind == .struct_ { | ||
// Add fields, but only if it's a struct. | ||
struct_info := sym.info as ast.Struct | ||
// match struct_info { | ||
// ast.Struct | ||
//} | ||
for field in struct_info.fields { | ||
field_sym := c.table.sym(field.typ) | ||
fields << ACFieldMethod{field.name, field_sym.name} | ||
} | ||
} else if sym.kind == .array { | ||
// t := typeof(sym.info).name | ||
if sym.info is ast.Aggregate { | ||
} else if sym.info is ast.Array { | ||
fields << ACFieldMethod{'len', 'int'} | ||
fields << ACFieldMethod{'cap', 'int'} | ||
} | ||
// array_info := sym.info as ast.Array | ||
} | ||
// Aliases and other types can have methods, add them | ||
for method in sym.methods { | ||
method_ret_type := c.table.sym(method.return_type) | ||
fields << ACFieldMethod{build_method_summary(method), method_ret_type.name} | ||
} | ||
fields.sort(a.name < b.name) | ||
for field in fields { | ||
sb.writeln('${field.name}:${field.typ}') | ||
} | ||
res := sb.str().trim_space() | ||
if res != '' { | ||
println(res) | ||
c.pref.linfo.vars_printed[nt] = true | ||
} | ||
} | ||
} | ||
|
||
fn build_method_summary(method ast.Fn) string { | ||
mut s := method.name + '(' | ||
for i, param in method.params { | ||
s += param.name | ||
if i < method.params.len - 1 { | ||
s += ',' | ||
} | ||
} | ||
return s + ')' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved. | ||
// Use of this source code is governed by an MIT license that can be found in the LICENSE file. | ||
module pref | ||
|
||
// import v.ast | ||
// import v.pref | ||
// import os | ||
|
||
// fn (mut p Pref) parse_line_info(line string, all_ast_files []&ast.File) { | ||
fn (mut p Preferences) parse_line_info(line string) { | ||
// println("parse_line_info '${line}'") | ||
format_err := 'wrong format, use `-line-info "file.v:24:expr_to_look_up"' | ||
vals := line.split(':') | ||
if vals.len != 3 { | ||
eprintln(format_err) | ||
return | ||
} | ||
file_name := vals[0] | ||
line_nr := vals[1].int() - 1 | ||
expr := vals[2] | ||
if !file_name.ends_with('.v') || line_nr == -1 { | ||
eprintln(format_err) | ||
return | ||
} | ||
|
||
// println('files.len=${c.files.len}') | ||
// Find which file contains the line | ||
mut found := true // false | ||
//// mut found_path := '' | ||
// mut found_file_idx := -1 | ||
/* | ||
for i, file in all_ast_files { | ||
// base := os.base(file.path) | ||
base := file.path // os.base(file.path) | ||
// println(base) | ||
if base == file_name { | ||
if found { | ||
eprintln('more than one "${file_name}" found: "${file.path}" and "${found_path}"') | ||
return | ||
} | ||
found = true | ||
found_path = file.path | ||
found_file_idx = i | ||
} | ||
} | ||
*/ | ||
|
||
if !found { | ||
eprintln('file "${file_name}" not found among those parsed') | ||
return | ||
} | ||
|
||
p.linfo = LineInfo{ | ||
line_nr: line_nr | ||
path: file_name | ||
expr: expr | ||
} | ||
} | ||
|
||
pub fn add_line_info_expr_to_program_text(raw_text string, linfo LineInfo) string { | ||
lines := raw_text.split('\n') | ||
lines_before := lines[..linfo.line_nr].join('\n') | ||
mut expr := linfo.expr | ||
if !expr.contains('.') { | ||
// Single variable, `foo` => `foo.xx` | ||
// expr += '.xxx' | ||
// expr = '_ = ' + expr | ||
expr = 'println(' + expr + ')' | ||
} | ||
lines_after := lines[linfo.line_nr..].join('\n') | ||
return lines_before + '\n' + expr + '\n' + lines_after | ||
} |
Oops, something went wrong.