1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-08 15:19:40 -05:00

chore(lsp): log more for "unexpected positions" lsp error (#13815)

Ref #13657
This commit is contained in:
David Sherret 2022-03-02 16:06:38 -05:00 committed by GitHub
parent 9de5275030
commit e8c47755bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 9 deletions

View file

@ -159,12 +159,19 @@ impl IndexValid {
}
#[derive(Debug, Clone)]
pub(crate) enum AssetOrDocument {
pub enum AssetOrDocument {
Document(Document),
Asset(AssetDocument),
}
impl AssetOrDocument {
pub fn specifier(&self) -> &ModuleSpecifier {
match self {
AssetOrDocument::Asset(asset) => asset.specifier(),
AssetOrDocument::Document(doc) => doc.specifier(),
}
}
pub fn document(&self) -> Option<&Document> {
match self {
AssetOrDocument::Asset(_) => None,
@ -211,6 +218,10 @@ impl AssetOrDocument {
pub fn document_lsp_version(&self) -> Option<i32> {
self.document().and_then(|d| d.maybe_lsp_version())
}
pub fn is_open(&self) -> bool {
self.document().map(|d| d.is_open()).unwrap_or(false)
}
}
#[derive(Debug, Clone)]
@ -229,7 +240,7 @@ struct DocumentInner {
}
#[derive(Debug, Clone)]
pub(crate) struct Document(Arc<DocumentInner>);
pub struct Document(Arc<DocumentInner>);
impl Document {
fn new(

View file

@ -2197,7 +2197,7 @@ impl Inner {
})?;
let semantic_tokens =
semantic_classification.to_semantic_tokens(line_index)?;
semantic_classification.to_semantic_tokens(&asset_or_doc, line_index)?;
let response = if !semantic_tokens.data.is_empty() {
Some(SemanticTokensResult::Tokens(semantic_tokens))
} else {
@ -2240,7 +2240,7 @@ impl Inner {
})?;
let semantic_tokens =
semantic_classification.to_semantic_tokens(line_index)?;
semantic_classification.to_semantic_tokens(&asset_or_doc, line_index)?;
let response = if !semantic_tokens.data.is_empty() {
Some(SemanticTokensRangeResult::Tokens(semantic_tokens))
} else {

View file

@ -2,6 +2,7 @@
use super::code_lens;
use super::config;
use super::documents::AssetOrDocument;
use super::language_server;
use super::language_server::StateSnapshot;
use super::performance::Performance;
@ -155,6 +156,7 @@ impl TsServer {
#[derive(Debug, Clone)]
struct AssetDocumentInner {
specifier: ModuleSpecifier,
text: Arc<String>,
length: usize,
line_index: Arc<LineIndex>,
@ -167,9 +169,10 @@ struct AssetDocumentInner {
pub struct AssetDocument(Arc<AssetDocumentInner>);
impl AssetDocument {
pub fn new(text: impl AsRef<str>) -> Self {
pub fn new(specifier: ModuleSpecifier, text: impl AsRef<str>) -> Self {
let text = text.as_ref();
Self(Arc::new(AssetDocumentInner {
specifier,
text: Arc::new(text.to_string()),
length: text.encode_utf16().count(),
line_index: Arc::new(LineIndex::new(text)),
@ -177,6 +180,10 @@ impl AssetDocument {
}))
}
pub fn specifier(&self) -> &ModuleSpecifier {
&self.0.specifier
}
pub fn with_navigation_tree(
&self,
tree: Arc<NavigationTree>,
@ -216,7 +223,7 @@ fn new_assets_map() -> Arc<Mutex<AssetsMap>> {
.map(|(k, v)| {
let url_str = format!("asset:///{}", k);
let specifier = resolve_url(&url_str).unwrap();
let asset = AssetDocument::new(v);
let asset = AssetDocument::new(specifier.clone(), v);
(specifier, Some(asset))
})
.collect();
@ -332,14 +339,15 @@ async fn get_asset(
) -> Result<Option<AssetDocument>, AnyError> {
let specifier_str = specifier.to_string().replace("asset:///", "");
if let Some(text) = tsc::get_asset(&specifier_str) {
let maybe_asset = Some(AssetDocument::new(text));
let maybe_asset = Some(AssetDocument::new(specifier.clone(), text));
Ok(maybe_asset)
} else {
let res = ts_server
.request(state_snapshot, RequestMethod::GetAsset(specifier.clone()))
.await?;
let maybe_text: Option<String> = serde_json::from_value(res)?;
let maybe_asset = maybe_text.map(AssetDocument::new);
let maybe_asset =
maybe_text.map(|text| AssetDocument::new(specifier.clone(), text));
Ok(maybe_asset)
}
}
@ -1420,6 +1428,7 @@ pub struct Classifications {
impl Classifications {
pub fn to_semantic_tokens(
&self,
asset_or_doc: &AssetOrDocument,
line_index: Arc<LineIndex>,
) -> LspResult<lsp::SemanticTokens> {
let token_count = self.spans.len() / 3;
@ -1452,7 +1461,9 @@ impl Classifications {
);
} else {
log::error!(
"unexpected positions\nstart_pos: {:?}\nend_pos: {:?}",
"unexpected positions\nspecifier: {}\nopen: {}\nstart_pos: {:?}\nend_pos: {:?}",
asset_or_doc.specifier(),
asset_or_doc.is_open(),
start_pos,
end_pos
);