Skip to content

Commit

Permalink
minor improvements for LSP
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaquraish committed Mar 31, 2024
1 parent 7d8702c commit f8be1d9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion compiler/lsp/mod.oc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def handle_document_symbols(program: &Program, path: str) {

let doc_ns: &Namespace = null
for ns : program.iter_namespaces() {
let ns_filename = ns.sym.span.start.filename
let ns_filename = ns.span.start.filename
if ns_filename? and ns_filename.eq(path) {
doc_ns = ns
break
Expand Down
12 changes: 10 additions & 2 deletions compiler/parser.oc
Original file line number Diff line number Diff line change
Expand Up @@ -2120,11 +2120,11 @@ def Parser::create_namespaces_for_initial_file(&this, filename: str, single_file

// If we didn't find a root, treat this as a standalone file. Only create one
// directory above the file itself.
let start: i32 = if found_root then namespace_paths.size as i32 - 1 else 0
let start: i32 = if found_root then namespace_paths.size as i32 else 0

// Create all the necessary namespaces
let cur_ns = .program.global
for let i = start; i >= 0; i -= 1 {
for let i = start - 1; i >= 0; i -= 1 {
let path = namespace_paths.data[i]
let t1 = path.copy()
let base = basename(t1).copy()
Expand Down Expand Up @@ -2158,6 +2158,14 @@ def Parser::create_namespaces_for_initial_file(&this, filename: str, single_file
return
}

// This almost certainly means we're looking at something that's in the standard library.
// This is likely happening in LSP mode, so we don't particularly care about adjusting the
// `full_name` field of the symbol here since we're not going to make it to codegen anyway.
if cur_ns.namespaces.contains(file_base) {
.ns = cur_ns.namespaces.at(file_base)
return
}

// Create the namespace for the file
let child_ns = Namespace::new(parent: cur_ns, path: filename)
child_ns.sym = Symbol::new(Namespace,
Expand Down
2 changes: 1 addition & 1 deletion compiler/passes/generic_pass.oc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import std::vector::Vector
import std::span::Span
import std::libc::calloc
import @ast::scopes::{ Scope, Symbol, SymbolType }
import @ast::program::{ Program, Namespace }
import @errors::Error
import @types::{ Type, BaseType }
import @ast::nodes::{ AST, Function, Structure, Enum, Variable }
import std::libc::calloc

//* Base class for passes
//*
Expand Down
2 changes: 1 addition & 1 deletion compiler/passes/typechecker.oc
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ def TypeChecker::check_expression_helper(&this, node: &AST, hint: &Type): &Type
}
if not lhs.eq(rhs) {
.error(Error::new(
node.span, `Variable type does not match assignment type, Expected type '{lhs.str()}', got '{rhs.str()}'`
node.u.binary.rhs.span, `Variable type does not match assignment type, Expected type '{lhs.str()}', got '{rhs.str()}'`
))
}
return lhs
Expand Down
6 changes: 3 additions & 3 deletions compiler/types.oc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//* Contains the structs for the type system.

import @ast::nodes::{ AST, ASTType, Structure, Enum, Variable, Function }
import @ast::scopes::{ Symbol, TemplateInstance }
import @ast::program::Namespace
import std::buffer::Buffer
import std::vector::Vector
import std::map::Map
import std::span::Span
import std::libc::calloc
import @ast::nodes::{ AST, ASTType, Structure, Enum, Variable, Function }
import @ast::scopes::{ Symbol, TemplateInstance }
import @ast::program::Namespace
import @tokens::{ Token, TokenType }

enum BaseType {
Expand Down

0 comments on commit f8be1d9

Please sign in to comment.