-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add analyze tool to Developer extension
#4530
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
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
97343cc
initial refactor
tlongwell-block 5eb5c18
v2 work
tlongwell-block 1a02c18
v3 structure
tlongwell-block b50ed43
semantic overhaul
tlongwell-block d610d55
feature complete
tlongwell-block be636b7
clippy 1
tlongwell-block 0e93597
cleanup + lint
tlongwell-block 0afb0ad
semantic mode fix, pre-focus fix
tlongwell-block 4e1f194
focus
tlongwell-block f594c5d
focus 2
tlongwell-block 6b9ddf1
focus finish
tlongwell-block 0760588
description with flow
tlongwell-block d48b210
structure output
tlongwell-block 73aa521
symlink file support
tlongwell-block b505a91
whoops
tlongwell-block e1f399c
major refactor
tlongwell-block fc44115
refactor follow up
tlongwell-block 16f4435
fmt
tlongwell-block 83cd9ef
separate tests
tlongwell-block 35b5e61
test fixes
tlongwell-block c4ebf65
unrelated
tlongwell-block dfdaad4
linting
tlongwell-block 17ea82e
less cloning
tlongwell-block 00a4a7b
less async, more paralell
tlongwell-block cd0bb57
comment cleanup
tlongwell-block 67f1e39
More useful errors
tlongwell-block 31cb6e7
python enhance query
tlongwell-block 6eacf7d
duplicate queries removal
tlongwell-block 3de738f
cache lock poisoning management
tlongwell-block 4c0391c
large output warning and `force` parameter
tlongwell-block 8687383
large output tests
tlongwell-block dfb8682
Merge remote-tracking branch 'origin/main' into analyze_tool
tlongwell-block e3ec469
Merge branch 'main' into analyze_tool
michaelneale c5315fb
Kotlin support
tlongwell-block e8093a1
Merge origin/main into analyze_tool branch
tlongwell-block 1ea1565
enhanced tool description
tlongwell-block 7600ae3
slim description
tlongwell-block a8d12d0
feat: Add Swift support to analyze tool and downgrade tree-sitter to …
tlongwell-block d12723f
swift support
tlongwell-block 4376956
handle binaries more gracefully
tlongwell-block File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,86 @@ | ||
| use lru::LruCache; | ||
| use std::num::NonZeroUsize; | ||
| use std::path::PathBuf; | ||
| use std::sync::{Arc, Mutex}; | ||
| use std::time::SystemTime; | ||
|
|
||
| use super::lock_or_recover; | ||
| use crate::developer::analyze::types::AnalysisResult; | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct AnalysisCache { | ||
| cache: Arc<Mutex<LruCache<CacheKey, Arc<AnalysisResult>>>>, | ||
| #[allow(dead_code)] | ||
| max_size: usize, | ||
| } | ||
|
|
||
| #[derive(Hash, Eq, PartialEq, Debug, Clone)] | ||
| struct CacheKey { | ||
| path: PathBuf, | ||
| modified: SystemTime, | ||
| } | ||
|
|
||
| impl AnalysisCache { | ||
| pub fn new(max_size: usize) -> Self { | ||
| tracing::info!("Initializing analysis cache with size {}", max_size); | ||
|
|
||
| let size = NonZeroUsize::new(max_size).unwrap_or_else(|| { | ||
| tracing::warn!("Invalid cache size {}, using default 100", max_size); | ||
| NonZeroUsize::new(100).unwrap() | ||
| }); | ||
|
|
||
| Self { | ||
| cache: Arc::new(Mutex::new(LruCache::new(size))), | ||
| max_size, | ||
| } | ||
| } | ||
|
|
||
| pub fn get(&self, path: &PathBuf, modified: SystemTime) -> Option<AnalysisResult> { | ||
| let mut cache = lock_or_recover(&self.cache, |c| c.clear()); | ||
| let key = CacheKey { | ||
| path: path.clone(), | ||
| modified, | ||
| }; | ||
|
|
||
| if let Some(result) = cache.get(&key) { | ||
| tracing::trace!("Cache hit for {:?}", path); | ||
| Some((**result).clone()) | ||
| } else { | ||
| tracing::trace!("Cache miss for {:?}", path); | ||
| None | ||
| } | ||
| } | ||
|
|
||
| pub fn put(&self, path: PathBuf, modified: SystemTime, result: AnalysisResult) { | ||
| let mut cache = lock_or_recover(&self.cache, |c| c.clear()); | ||
| let key = CacheKey { | ||
| path: path.clone(), | ||
| modified, | ||
| }; | ||
|
|
||
| tracing::trace!("Caching result for {:?}", path); | ||
| cache.put(key, Arc::new(result)); | ||
| } | ||
|
|
||
| pub fn clear(&self) { | ||
| let mut cache = lock_or_recover(&self.cache, |c| c.clear()); | ||
| cache.clear(); | ||
| tracing::debug!("Cache cleared"); | ||
| } | ||
|
|
||
| pub fn len(&self) -> usize { | ||
| let cache = lock_or_recover(&self.cache, |c| c.clear()); | ||
| cache.len() | ||
| } | ||
|
|
||
| pub fn is_empty(&self) -> bool { | ||
| let cache = lock_or_recover(&self.cache, |c| c.clear()); | ||
| cache.is_empty() | ||
| } | ||
| } | ||
|
|
||
| impl Default for AnalysisCache { | ||
| fn default() -> Self { | ||
| Self::new(100) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.