Skip to content

Commit

Permalink
Revert "update imports"
Browse files Browse the repository at this point in the history
This reverts commit b65e338.
  • Loading branch information
ttytm committed Mar 17, 2024
1 parent b65e338 commit 2659aaa
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 60 deletions.
10 changes: 5 additions & 5 deletions analyzer/parser/parser.v
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module parser

import tree_sitter { NodeType, Tree }
import tree_sitter as ts
import os

// ParseResult represents the result of a parsing operation.
pub struct ParseResult {
pub:
tree &Tree[NodeType] = unsafe { nil } // Resulting tree or nil if the source could not be parsed.
tree &ts.Tree[ts.NodeType] = unsafe { nil } // Resulting tree or nil if the source could not be parsed.
source_text string // Source code.
pub mut:
path string // Path of the file that was parsed.
Expand Down Expand Up @@ -94,9 +94,9 @@ pub fn parse_code(code string) ParseResult {
// res2 = parser.parse_code_with_tree(code2, res.tree)
// println(res2.tree
// }
pub fn parse_code_with_tree(code string, old_tree &Tree[NodeType]) ParseResult {
mut parser := tree_sitter.new_parser[NodeType](tree_sitter.type_factory)
parser.set_language(tree_sitter.language)
pub fn parse_code_with_tree(code string, old_tree &ts.Tree[ts.NodeType]) ParseResult {
mut parser := ts.new_parser[ts.NodeType](ts.type_factory)
parser.set_language(ts.language)
raw_tree := if isnil(old_tree) { unsafe { nil } } else { old_tree.raw_tree }
tree := parser.parse_string(source: code, tree: raw_tree)
return ParseResult{
Expand Down
4 changes: 2 additions & 2 deletions analyzer/psi/AstNode.v
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module psi

import tree_sitter
import tree_sitter as ts

pub fn (node AstNode) parent_of_type(typ tree_sitter.NodeType) ?AstNode {
pub fn (node AstNode) parent_of_type(typ ts.NodeType) ?AstNode {
mut res := node
for {
res = res.parent()?
Expand Down
28 changes: 14 additions & 14 deletions analyzer/psi/PsiElement.v
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module psi

import tree_sitter { Node, NodeType }
import tree_sitter as ts

pub type ID = int

pub type AstNode = Node[NodeType]
pub type AstNode = ts.Node[ts.NodeType]

pub interface PsiElement {
node AstNode // base node from Tree Sitter
containing_file &PsiFile // file where the element is located
stub_id StubId
get_stub() ?&StubBase
stub_list() &StubList
element_type() NodeType
element_type() ts.NodeType
node() AstNode // return base node from Tree Sitter
containing_file() &PsiFile // return file where the element is located
is_equal(other PsiElement) bool // return true if the element is equal to the other element
Expand All @@ -31,21 +31,21 @@ pub interface PsiElement {
parent_nth(depth int) ?PsiElement
// parent_of_type returns the parent node with the specified type.
// If no such node exists, none is returned.
parent_of_type(typ NodeType) ?PsiElement
parent_of_type(typ ts.NodeType) ?PsiElement
// parent_of_any_type returns the parent node with one of the specified types.
// If no such node exists, none is returned.
parent_of_any_type(types ...NodeType) ?PsiElement
parent_of_any_type(types ...ts.NodeType) ?PsiElement
// inside returns true if the node is inside a node with the specified type.
inside(typ NodeType) bool
inside(typ ts.NodeType) bool
// is_parent_of returns true if the passed node is a child of the given node.
is_parent_of(element PsiElement) bool
// sibling_of_type_backward returns the previous node at the same nesting level with the specified type.
// If no such node exists, none is returned.
sibling_of_type_backward(typ NodeType) ?PsiElement
sibling_of_type_backward(typ ts.NodeType) ?PsiElement
// parent_of_type_or_self returns the parent node with the specified type, or the
// node itself if its type matches the specified one.
// If no such node exists, none is returned.
parent_of_type_or_self(typ NodeType) ?PsiElement
parent_of_type_or_self(typ ts.NodeType) ?PsiElement
// children returns all child nodes.
children() []PsiElement
// named_children returns child nodes except unknown nodes.
Expand Down Expand Up @@ -73,27 +73,27 @@ pub interface PsiElement {
prev_sibling() ?PsiElement
// prev_sibling_of_type returns the previous node at the same nesting level with the specified type.
// If no such node exists, none is returned.
prev_sibling_of_type(typ NodeType) ?PsiElement
prev_sibling_of_type(typ ts.NodeType) ?PsiElement
// prev_sibling_or_stub returns the previous node at the same nesting level or stub.
// If the node is the first child node or stub, none is returned.
prev_sibling_or_stub() ?PsiElement
// find_child_by_type returns the first child node with the specified type.
// If no such node is found, none is returned.
find_child_by_type(typ NodeType) ?PsiElement
find_child_by_type(typ ts.NodeType) ?PsiElement
// has_child_of_type returns true if the node has a child with the specified type.
has_child_of_type(typ NodeType) bool
has_child_of_type(typ ts.NodeType) bool
// find_child_by_type_or_stub returns the first child node with the specified type or stub.
// If no such node is found, none is returned.
find_child_by_type_or_stub(typ NodeType) ?PsiElement
find_child_by_type_or_stub(typ ts.NodeType) ?PsiElement
// find_child_by_name returns the first child node with the specified name.
// If no such node is found, none is returned.
find_child_by_name(name string) ?PsiElement
// find_children_by_type returns all child nodes with the specified type.
// If no such nodes are found, an empty array is returned.
find_children_by_type(typ NodeType) []PsiElement
find_children_by_type(typ ts.NodeType) []PsiElement
// find_children_by_type_or_stub returns all child nodes with the specified type or stub.
// If no such nodes are found, an empty array is returned.
find_children_by_type_or_stub(typ NodeType) []PsiElement
find_children_by_type_or_stub(typ ts.NodeType) []PsiElement
// get_text returns the text of the node.
get_text() string
// text_matches returns true if the text of the node matches the specified value.
Expand Down
28 changes: 14 additions & 14 deletions analyzer/psi/PsiElementImpl.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module psi

import tree_sitter { NodeType }
import tree_sitter as ts

pub struct PsiElementImpl {
pub:
Expand Down Expand Up @@ -48,7 +48,7 @@ pub fn (n &PsiElementImpl) stub_list() &StubList {
return n.stubs_list
}

pub fn (n &PsiElementImpl) element_type() NodeType {
pub fn (n &PsiElementImpl) element_type() ts.NodeType {
if stub := n.get_stub() {
return stub.element_type()
}
Expand Down Expand Up @@ -138,7 +138,7 @@ pub fn (n &PsiElementImpl) parent_nth(depth int) ?PsiElement {
return create_element(parent, n.containing_file)
}

pub fn (n &PsiElementImpl) parent_of_type(typ NodeType) ?PsiElement {
pub fn (n &PsiElementImpl) parent_of_type(typ ts.NodeType) ?PsiElement {
mut res := PsiElement(n)
for {
res = res.parent()?
Expand All @@ -150,7 +150,7 @@ pub fn (n &PsiElementImpl) parent_of_type(typ NodeType) ?PsiElement {
return none
}

pub fn (n &PsiElementImpl) parent_of_any_type(types ...NodeType) ?PsiElement {
pub fn (n &PsiElementImpl) parent_of_any_type(types ...ts.NodeType) ?PsiElement {
mut res := PsiElement(n)
for {
res = res.parent()?
Expand All @@ -163,7 +163,7 @@ pub fn (n &PsiElementImpl) parent_of_any_type(types ...NodeType) ?PsiElement {
return none
}

pub fn (n &PsiElementImpl) inside(typ NodeType) bool {
pub fn (n &PsiElementImpl) inside(typ ts.NodeType) bool {
mut res := PsiElement(n)
for {
res = res.parent() or { return false }
Expand Down Expand Up @@ -196,7 +196,7 @@ pub fn (n &PsiElementImpl) is_parent_of(element PsiElement) bool {
return false
}

pub fn (n &PsiElementImpl) sibling_of_type_backward(typ NodeType) ?PsiElement {
pub fn (n &PsiElementImpl) sibling_of_type_backward(typ ts.NodeType) ?PsiElement {
mut res := PsiElement(n)
for {
res = res.prev_sibling_or_stub()?
Expand All @@ -208,7 +208,7 @@ pub fn (n &PsiElementImpl) sibling_of_type_backward(typ NodeType) ?PsiElement {
return none
}

pub fn (n &PsiElementImpl) parent_of_type_or_self(typ NodeType) ?PsiElement {
pub fn (n &PsiElementImpl) parent_of_type_or_self(typ ts.NodeType) ?PsiElement {
if n.node.type_name == typ {
return create_element(n.node, n.containing_file)
}
Expand Down Expand Up @@ -311,7 +311,7 @@ pub fn (n &PsiElementImpl) prev_sibling() ?PsiElement {
return create_element(sibling, n.containing_file)
}

pub fn (n &PsiElementImpl) prev_sibling_of_type(typ NodeType) ?PsiElement {
pub fn (n &PsiElementImpl) prev_sibling_of_type(typ ts.NodeType) ?PsiElement {
mut res := PsiElement(n)
for {
res = res.prev_sibling_or_stub()?
Expand All @@ -335,12 +335,12 @@ pub fn (n &PsiElementImpl) prev_sibling_or_stub() ?PsiElement {
return n.prev_sibling()
}

pub fn (n &PsiElementImpl) find_child_by_type(typ NodeType) ?PsiElement {
pub fn (n &PsiElementImpl) find_child_by_type(typ ts.NodeType) ?PsiElement {
ast_node := n.node.first_node_by_type(typ)?
return create_element(ast_node, n.containing_file)
}

pub fn (n &PsiElementImpl) has_child_of_type(typ NodeType) bool {
pub fn (n &PsiElementImpl) has_child_of_type(typ ts.NodeType) bool {
if stub := n.get_stub() {
return stub.has_child_of_type(node_type_to_stub_type(typ))
}
Expand All @@ -352,7 +352,7 @@ pub fn (n &PsiElementImpl) has_child_of_type(typ NodeType) bool {
return false
}

pub fn (n &PsiElementImpl) find_child_by_type_or_stub(typ NodeType) ?PsiElement {
pub fn (n &PsiElementImpl) find_child_by_type_or_stub(typ ts.NodeType) ?PsiElement {
if stub := n.get_stub() {
child := stub.get_child_by_type(node_type_to_stub_type(typ))?
return child.get_psi()
Expand All @@ -367,7 +367,7 @@ pub fn (n &PsiElementImpl) find_child_by_name(name string) ?PsiElement {
return create_element(ast_node, n.containing_file)
}

pub fn (n &PsiElementImpl) find_children_by_type(typ NodeType) []PsiElement {
pub fn (n &PsiElementImpl) find_children_by_type(typ ts.NodeType) []PsiElement {
mut result := []PsiElement{}
mut child := n.node.first_child() or { return [] }
for {
Expand All @@ -379,7 +379,7 @@ pub fn (n &PsiElementImpl) find_children_by_type(typ NodeType) []PsiElement {
return result
}

pub fn (n &PsiElementImpl) find_children_by_type_or_stub(typ NodeType) []PsiElement {
pub fn (n &PsiElementImpl) find_children_by_type_or_stub(typ ts.NodeType) []PsiElement {
if stub := n.get_stub() {
return stub.get_children_by_type(node_type_to_stub_type(typ)).get_psi()
}
Expand All @@ -395,7 +395,7 @@ pub fn (n &PsiElementImpl) find_children_by_type_or_stub(typ NodeType) []PsiElem
return result
}

pub fn (n &PsiElementImpl) find_last_child_by_type(typ NodeType) ?PsiElement {
pub fn (n &PsiElementImpl) find_last_child_by_type(typ ts.NodeType) ?PsiElement {
ast_node := n.node.last_node_by_type(typ)?
return create_element(ast_node, n.containing_file)
}
Expand Down
6 changes: 3 additions & 3 deletions analyzer/psi/PsiFile.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import lsp
import time
import utils
import loglib
import tree_sitter { NodeType, Tree }
import tree_sitter as ts
import analyzer.parser

@[heap]
Expand All @@ -13,12 +13,12 @@ pub:
path string
stub_list &StubList = unsafe { nil }
pub mut:
tree &Tree[NodeType] = unsafe { nil }
tree &ts.Tree[ts.NodeType] = unsafe { nil }
source_text string
root PsiElement
}

pub fn new_psi_file(path string, tree &Tree[NodeType], source_text string) &PsiFile {
pub fn new_psi_file(path string, tree &ts.Tree[ts.NodeType], source_text string) &PsiFile {
mut file := &PsiFile{
path: path
tree: unsafe { tree }
Expand Down
4 changes: 2 additions & 2 deletions analyzer/psi/PsiNamedElement.v
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module psi

import tree_sitter
import tree_sitter as ts

pub interface PsiNamedElement {
parent_of_type(typ tree_sitter.NodeType) ?PsiElement
parent_of_type(typ ts.NodeType) ?PsiElement
identifier_text_range() TextRange
identifier() ?PsiElement
name() string
Expand Down
4 changes: 2 additions & 2 deletions analyzer/psi/StubBase.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module psi

import tree_sitter
import tree_sitter as ts

pub type StubId = int

Expand Down Expand Up @@ -74,7 +74,7 @@ pub fn (s &StubBase) stub_type() StubType {
return s.stub_type
}

pub fn (s &StubBase) element_type() tree_sitter.NodeType {
pub fn (s &StubBase) element_type() ts.NodeType {
return match s.stub_type {
.root { .unknown }
.function_declaration { .function_declaration }
Expand Down
4 changes: 2 additions & 2 deletions analyzer/psi/StubbedElementTypeImpl.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module psi

import utils
import tree_sitter
import tree_sitter as ts

pub enum StubType as u8 {
root
Expand Down Expand Up @@ -60,7 +60,7 @@ pub enum StubType as u8 {
embedded_definition
}

pub fn node_type_to_stub_type(typ tree_sitter.NodeType) StubType {
pub fn node_type_to_stub_type(typ ts.NodeType) StubType {
return match typ {
.function_declaration { .function_declaration }
.receiver { .receiver }
Expand Down
4 changes: 2 additions & 2 deletions analyzer/psi/TreeWalker.v
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module psi

import tree_sitter
import tree_sitter as ts

struct TreeWalker {
mut:
already_visited_children bool
cursor tree_sitter.TreeCursor[tree_sitter.NodeType] @[required]
cursor ts.TreeCursor[ts.NodeType] @[required]
}

pub fn (mut tw TreeWalker) next() ?AstNode {
Expand Down
6 changes: 3 additions & 3 deletions tree_sitter/examples/cursor.v
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module main

import tree_sitter
import tree_sitter as ts

fn main() {
mut p := tree_sitter.new_parser[tree_sitter.NodeType](ts.type_factory)
p.set_language(tree_sitter.language)
mut p := ts.new_parser[ts.NodeType](ts.type_factory)
p.set_language(ts.language)

code := '
fn foo() int {
Expand Down
6 changes: 3 additions & 3 deletions tree_sitter/examples/simple.v
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module main

import tree_sitter
import tree_sitter as ts

fn main() {
mut p := tree_sitter.new_parser[tree_sitter.NodeType](ts.type_factory)
p.set_language(tree_sitter.language)
mut p := ts.new_parser[ts.NodeType](ts.type_factory)
p.set_language(ts.language)

code := 'fn main() {}'
tree := p.parse_string(source: code)
Expand Down
6 changes: 3 additions & 3 deletions tree_sitter/examples/with_old_tree.v
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module main

import time
import tree_sitter
import tree_sitter as ts

fn main() {
mut p := tree_sitter.new_parser[tree_sitter.NodeType](tree_sitter.type_factory)
p.set_language(tree_sitter.language)
mut p := ts.new_parser[ts.NodeType](ts.type_factory)
p.set_language(ts.language)

code := '
fn foo() int {
Expand Down
6 changes: 3 additions & 3 deletions tree_sitter/simple_test.v
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import tree_sitter
import tree_sitter as ts

fn test_simple() {
mut p := tree_sitter.new_parser[tree_sitter.NodeType](tree_sitter.type_factory)
p.set_language(tree_sitter.language)
mut p := ts.new_parser[ts.NodeType](ts.type_factory)
p.set_language(ts.language)

code := 'fn main() {}'
tree := p.parse_string(source: code)
Expand Down
Loading

0 comments on commit 2659aaa

Please sign in to comment.