Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of the mainpath setting #336

Merged
merged 21 commits into from
Sep 14, 2023
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
2 changes: 0 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}/editors/code"
],
"outFiles": [
Expand All @@ -29,7 +28,6 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}/editors/code"
],
"outFiles": [
Expand Down
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## Release Notes

## [0.11.0]

### Added

- Added automatic mainPath detection. The mainPath setting does not exist anymore!
- Added support for Apple Silicon.
- Switched to a path interner for better performance when resolving references (no longer using URIs).
- Added better progress report.

## [0.10.19]

### Added
Expand Down Expand Up @@ -291,15 +300,15 @@
### Added

- Added status notifications.
- Added support for folder rename in includeDirectories.
- Added support for folder rename in includesDirectories.

## [0.6.0]

### Added

- Added `typedef` and `typeset` support.
- Added callback completions.
- Added file rename/deletion support in includeDirectories.
- Added file rename/deletion support in includesDirectories.

## [0.5.1]

Expand All @@ -309,7 +318,7 @@

### Fixed

- Fixed changes in IncludeDirectories not being detected.
- Fixed changes in IncludesDirectories not being detected.
- Fixed some references not being resolved on the initial parse.

## [0.5.0]
Expand Down
44 changes: 38 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ tree-sitter-sourcepawn = { git = "https://github.com/Sarrus1/tree-sitter-sourcep
strip_bom = "1.0.0"
serde = "1.0.147"
serde_json = "^1.0.83"
nohash-hasher = "^0.2.0"
indexmap = "^2.0.0"

[workspace.dependencies.uuid]
version = "1.3.0"
Expand Down
32 changes: 19 additions & 13 deletions crates/linter/src/spcomp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Context};
use anyhow::{anyhow, bail};
use fxhash::FxHashMap;
use lazy_static::lazy_static;
use lsp_types::{Diagnostic, DiagnosticSeverity, Position, Range, Url};
Expand Down Expand Up @@ -93,31 +93,37 @@ impl SPCompDiagnostic {
/// # Arguments
///
/// * `uri` - [Uri](Url) of the file to compile.
/// * `spcomp_path` - [Path](Path) of the spcomp executable.
/// * `includes_directories` - [Paths](PathBuf) of include directories to pass to spcomp.
/// * `linter_arguments` - Additional arguments to pass to spcomp.
pub fn get_spcomp_diagnostics(
uri: Url,
spcomp_path: &Path,
includes_directories: &[PathBuf],
linter_arguments: &[String],
) -> anyhow::Result<FxHashMap<Url, Vec<SPCompDiagnostic>>> {
let output = Command::new(
spcomp_path
.to_str()
.context("Failed to convert spcomp path to string.")?,
)
.args(build_args(&uri, includes_directories, linter_arguments)?)
.output();
// Handle Apple Silicon
let output = if std::env::consts::OS == "macos" && std::env::consts::ARCH == "aarch64" {
Command::new("arch")
.arg("-x86_64")
.arg(spcomp_path)
.args(build_args(&uri, includes_directories, linter_arguments)?)
.output()
} else {
Command::new(spcomp_path)
.args(build_args(&uri, includes_directories, linter_arguments)?)
.output()
};

let out_path = get_out_path();
if out_path.exists() {
let _ = fs::remove_file(out_path);
}

let output = output?;
let output = output?; // Unwrap output here to allow removing the existing file first.
let stderr = String::from_utf8_lossy(&output.stderr);
if !stderr.is_empty() {
return Err(anyhow::anyhow!(
"Failed to run spcomp with error: {}",
stderr
));
bail!("Failed to run spcomp with error: {}", stderr);
}

let stdout = String::from_utf8_lossy(&output.stdout);
Expand Down
4 changes: 3 additions & 1 deletion crates/parser/src/comment_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ impl<'a> Parser<'a> {
}

pub fn push_inline_comment(&mut self, item: &Arc<RwLock<SPItem>>) {
let Ok(description) = self.find_doc(item.read().range().end.line as usize, true) else {return};
let Ok(description) = self.find_doc(item.read().range().end.line as usize, true) else {
return;
};
match &mut *item.write() {
SPItem::EnumMember(enum_member_item) => {
enum_member_item.description = description;
Expand Down
1 change: 1 addition & 0 deletions crates/parser/src/define_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl<'a> Parser<'a> {
value: value.unwrap_or_default().to_string(),
description: self.find_doc(node.start_position().row, true)?,
uri: self.uri.clone(),
file_id: self.file_id,
references: vec![],
};

Expand Down
6 changes: 5 additions & 1 deletion crates/parser/src/enum_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl<'a> Parser<'a> {
v_full_range: self.build_v_range(&full_range),
description,
uri: self.uri.clone(),
file_id: self.file_id,
references: vec![],
children: vec![],
};
Expand Down Expand Up @@ -86,7 +87,9 @@ impl<'a> Parser<'a> {
"comment" => {
self.push_comment(child);
if let Some(items) = enum_item.read().children() {
let Some(item) = items.last()else{continue;};
let Some(item) = items.last() else {
continue;
};
self.push_inline_comment(item);
}
}
Expand All @@ -107,6 +110,7 @@ impl<'a> Parser<'a> {
let enum_member_item = EnumMemberItem {
name,
uri: self.uri.clone(),
file_id: self.file_id,
range,
v_range: self.build_v_range(&range),
parent: Arc::downgrade(enum_item),
Expand Down
2 changes: 2 additions & 0 deletions crates/parser/src/enum_struct_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl<'a> Parser<'a> {
v_full_range: self.build_v_range(&full_range),
description,
uri: self.uri.clone(),
file_id: self.file_id,
references: vec![],
children: vec![],
};
Expand Down Expand Up @@ -101,6 +102,7 @@ impl<'a> Parser<'a> {
v_range: self.build_v_range(&range),
description: Description::default(),
uri: self.uri.clone(),
file_id: self.file_id,
detail: format!("{} {}{}", type_, name, dimensions.join("")),
visibility: vec![],
storage_class: vec![],
Expand Down
2 changes: 2 additions & 0 deletions crates/parser/src/function_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl<'a> Parser<'a> {
v_full_range: self.build_v_range(&full_range),
description: description.clone(),
uri: self.uri.clone(),
file_id: self.file_id,
detail: attributes.build_detail(self.source).unwrap_or_default(),
visibility: attributes.visibility,
definition_type: attributes.definition_type,
Expand Down Expand Up @@ -259,6 +260,7 @@ impl<'a> Parser<'a> {
v_range: self.build_v_range(&range),
description: description.clone(),
uri: self.uri.clone(),
file_id: self.file_id,
detail: detail.to_string(),
visibility: vec![],
storage_class,
Expand Down
3 changes: 2 additions & 1 deletion crates/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lsp_types::{Range, Url};
use parking_lot::RwLock;
use preprocessor::Offset;
use std::sync::Arc;
use syntax::{comment::Comment, deprecated::Deprecated, SPItem};
use syntax::{comment::Comment, deprecated::Deprecated, FileId, SPItem};
use tree_sitter::Query;

pub mod comment_parser;
Expand Down Expand Up @@ -38,6 +38,7 @@ pub struct Parser<'a> {
pub offsets: &'a FxHashMap<u32, Vec<Offset>>,
pub source: &'a String,
pub uri: Arc<Url>,
pub file_id: FileId,
}

pub fn build_v_range(offsets: &FxHashMap<u32, Vec<Offset>>, range: &Range) -> Range {
Expand Down
1 change: 1 addition & 0 deletions crates/parser/src/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl<'a> Parser<'a> {
value: "".to_string(),
description: self.find_doc(node.start_position().row, true)?,
uri: self.uri.clone(),
file_id: self.file_id,
references: vec![],
};

Expand Down
1 change: 1 addition & 0 deletions crates/parser/src/methodmap_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl<'a> Parser<'a> {
.find_doc(node.start_position().row, false)
.unwrap_or_default(),
uri: self.uri.clone(),
file_id: self.file_id,
references: vec![],
tmp_parent: inherit,
children: vec![],
Expand Down
1 change: 1 addition & 0 deletions crates/parser/src/property_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl<'a> Parser<'a> {
.find_doc(node.start_position().row, false)
.unwrap_or_default(),
uri: self.uri.clone(),
file_id: self.file_id,
references: vec![],
parent: Arc::downgrade(&parent),
};
Expand Down
3 changes: 2 additions & 1 deletion crates/parser/src/typedef_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl<'a> Parser<'a> {
v_full_range: self.build_v_range(&full_range),
description: description.clone(),
uri: self.uri.clone(),
file_id: self.file_id,
detail: node
.utf8_text(self.source.as_bytes())
.unwrap_or_default()
Expand Down Expand Up @@ -159,7 +160,7 @@ impl<'a> Parser<'a> {

for child in argument_type_node.children(&mut cursor) {
match child.kind() {
// FIXME: Handle oldtypes.
// TODO: Handle oldtypes.
"type" => {
type_.name = child.utf8_text(self.source.as_bytes()).ok()?.to_string();
}
Expand Down
Loading
Loading