Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion ls/src/features/completion.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use async_lsp::lsp_types::{
CompletionContext, CompletionItem, CompletionItemKind,
CompletionItemLabelDetails, CompletionTriggerKind, InsertTextFormat,
Expand Down Expand Up @@ -75,7 +77,7 @@ const CONDITION_SUGGESTIONS: [(&str, Option<&str>); 16] = [
];

pub fn completion(
document: &Document,
document: Arc<Document>,
pos: Position,
context: Option<CompletionContext>,
) -> Option<Vec<CompletionItem>> {
Expand Down
6 changes: 4 additions & 2 deletions ls/src/features/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use async_lsp::lsp_types::{
Diagnostic, DiagnosticRelatedInformation, Location, Range,
};
Expand All @@ -23,7 +25,7 @@ pub struct Patch {

/// Returns a diagnostic vector for the given source code.
#[allow(unused_variables)]
pub fn diagnostics(document: &Document) -> Vec<Diagnostic> {
pub fn diagnostics(document: Arc<Document>) -> Vec<Diagnostic> {
#[allow(unused_mut)]
let mut diagnostics: Vec<Diagnostic> = Vec::new();

Expand All @@ -40,7 +42,7 @@ pub fn diagnostics(document: &Document) -> Vec<Diagnostic> {
/// comprehensive feedback including type checking, semantic analysis,
/// and pattern validation - not just syntax errors.
#[cfg(feature = "full-compiler")]
pub fn compiler_diagnostics(document: &Document) -> Vec<Diagnostic> {
pub fn compiler_diagnostics(document: Arc<Document>) -> Vec<Diagnostic> {
let source_code = SourceCode::from(document.text.as_str())
.with_origin(document.uri.clone());

Expand Down
4 changes: 3 additions & 1 deletion ls/src/features/document_highlight.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use async_lsp::lsp_types::{
DocumentHighlight, DocumentHighlightKind, Position,
};
Expand All @@ -17,7 +19,7 @@ use crate::utils::position::{node_to_range, token_to_range};
/// specified position is contained in a symbol, the response contains the
/// ranges of all occurrences of that symbol in the source code.
pub fn document_highlight(
document: &Document,
document: Arc<Document>,
pos: Position,
) -> Option<Vec<DocumentHighlight>> {
let cst = &document.cst;
Expand Down
5 changes: 4 additions & 1 deletion ls/src/features/document_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::sync::Arc;

use async_lsp::lsp_types::{DocumentSymbol, SymbolKind};
use yara_x_parser::ast::{Item, WithSpan, AST};

use crate::document::Document;

pub fn document_symbol(document: &Document, ast: AST) -> Vec<DocumentSymbol> {
pub fn document_symbol(document: Arc<Document>) -> Vec<DocumentSymbol> {
let line_index = &document.line_index;
let ast = AST::new(document.text.as_bytes(), document.cst.iter());
let mut symbols = Vec::new();
for item in ast.items {
match item {
Expand Down
9 changes: 5 additions & 4 deletions ls/src/features/goto.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::path::PathBuf;
use std::sync::Arc;

use async_lsp::lsp_types::{Location, Position, Url};
use yara_x_parser::cst::SyntaxKind;
Expand All @@ -13,7 +14,7 @@ use crate::utils::position::node_to_range;
/// Given a position that points some identifier, returns the range
/// of source code that contains the definition of that identifier.
pub fn go_to_definition(
document: &Document,
document: Arc<Document>,
pos: Position,
) -> Option<Location> {
let token = ident_at_position(&document.cst, pos)?;
Expand All @@ -38,7 +39,7 @@ pub fn go_to_definition(
}

fn go_to_rule_definition(
document: &Document,
document: Arc<Document>,
ident: &str,
) -> Option<Location> {
// Check if the rule is defined in the current document
Expand Down Expand Up @@ -82,9 +83,9 @@ fn go_to_rule_definition(
};

let uri = Url::from_file_path(abs_included_path).ok()?;
let document = Document::read(uri).ok()?;
let document = Arc::new(Document::read(uri).ok()?);

if let Some(location) = go_to_rule_definition(&document, ident) {
if let Some(location) = go_to_rule_definition(document, ident) {
return Some(location);
}
}
Expand Down
4 changes: 3 additions & 1 deletion ls/src/features/hover.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use async_lsp::lsp_types::{
HoverContents, MarkupContent, MarkupKind, Position,
};
Expand Down Expand Up @@ -71,7 +73,7 @@ impl RuleHoverBuilder {
}
}

pub fn hover(document: &Document, pos: Position) -> Option<HoverContents> {
pub fn hover(document: Arc<Document>, pos: Position) -> Option<HoverContents> {
// Find the token at the position where the user is hovering.
let token = token_at_position(&document.cst, pos)?;

Expand Down
4 changes: 3 additions & 1 deletion ls/src/features/references.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use async_lsp::lsp_types::{Position, Range};

use yara_x_parser::cst::SyntaxKind;
Expand All @@ -11,7 +13,7 @@ use crate::utils::position::{node_to_range, token_to_range};

/// Finds all references of a symbol at the given position in the text.
pub fn find_references(
document: &Document,
document: Arc<Document>,
pos: Position,
) -> Option<Vec<Range>> {
let cst = &document.cst;
Expand Down
4 changes: 3 additions & 1 deletion ls/src/features/selection_range.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use async_lsp::lsp_types::{Position, SelectionRange};

use yara_x_parser::cst::{Immutable, Node};
Expand All @@ -9,7 +11,7 @@ use crate::utils::position::{node_to_range, token_to_range};
/// Provides selection ranges from the given positions in the text
/// based on the given CST of this document.
pub fn selection_range(
document: &Document,
document: Arc<Document>,
positions: Vec<Position>,
) -> Option<Vec<SelectionRange>> {
let mut result: Vec<SelectionRange> = Vec::new();
Expand Down
5 changes: 3 additions & 2 deletions ls/src/features/semantic_tokens.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::VecDeque;
use std::sync::Arc;

use async_lsp::lsp_types;
use async_lsp::lsp_types::{
Expand Down Expand Up @@ -178,7 +179,7 @@ struct SemanticTokensIter {
}

impl SemanticTokensIter {
fn new(document: &Document, range: Option<Range>) -> Self {
fn new(document: Arc<Document>, range: Option<Range>) -> Self {
let first_token = if let Some(range) = range {
document.cst.root().token_at_position::<Utf16, _>((
range.start.line as usize,
Expand Down Expand Up @@ -330,7 +331,7 @@ impl Iterator for SemanticTokensIter {
/// An optional range can be specified, in which case only the tokens in that
/// range will be returned.
pub fn semantic_tokens(
document: &Document,
document: Arc<Document>,
range: Option<Range>,
) -> SemanticTokens {
let tokens = SemanticTokensIter::new(document, range);
Expand Down
Loading
Loading