mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
chore(lsp): log more for "unexpected positions" lsp error (#13815)
Ref #13657
This commit is contained in:
parent
9de5275030
commit
e8c47755bb
3 changed files with 31 additions and 9 deletions
|
@ -159,12 +159,19 @@ impl IndexValid {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) enum AssetOrDocument {
|
pub enum AssetOrDocument {
|
||||||
Document(Document),
|
Document(Document),
|
||||||
Asset(AssetDocument),
|
Asset(AssetDocument),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AssetOrDocument {
|
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> {
|
pub fn document(&self) -> Option<&Document> {
|
||||||
match self {
|
match self {
|
||||||
AssetOrDocument::Asset(_) => None,
|
AssetOrDocument::Asset(_) => None,
|
||||||
|
@ -211,6 +218,10 @@ impl AssetOrDocument {
|
||||||
pub fn document_lsp_version(&self) -> Option<i32> {
|
pub fn document_lsp_version(&self) -> Option<i32> {
|
||||||
self.document().and_then(|d| d.maybe_lsp_version())
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -229,7 +240,7 @@ struct DocumentInner {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct Document(Arc<DocumentInner>);
|
pub struct Document(Arc<DocumentInner>);
|
||||||
|
|
||||||
impl Document {
|
impl Document {
|
||||||
fn new(
|
fn new(
|
||||||
|
|
|
@ -2197,7 +2197,7 @@ impl Inner {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let semantic_tokens =
|
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() {
|
let response = if !semantic_tokens.data.is_empty() {
|
||||||
Some(SemanticTokensResult::Tokens(semantic_tokens))
|
Some(SemanticTokensResult::Tokens(semantic_tokens))
|
||||||
} else {
|
} else {
|
||||||
|
@ -2240,7 +2240,7 @@ impl Inner {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let semantic_tokens =
|
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() {
|
let response = if !semantic_tokens.data.is_empty() {
|
||||||
Some(SemanticTokensRangeResult::Tokens(semantic_tokens))
|
Some(SemanticTokensRangeResult::Tokens(semantic_tokens))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use super::code_lens;
|
use super::code_lens;
|
||||||
use super::config;
|
use super::config;
|
||||||
|
use super::documents::AssetOrDocument;
|
||||||
use super::language_server;
|
use super::language_server;
|
||||||
use super::language_server::StateSnapshot;
|
use super::language_server::StateSnapshot;
|
||||||
use super::performance::Performance;
|
use super::performance::Performance;
|
||||||
|
@ -155,6 +156,7 @@ impl TsServer {
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct AssetDocumentInner {
|
struct AssetDocumentInner {
|
||||||
|
specifier: ModuleSpecifier,
|
||||||
text: Arc<String>,
|
text: Arc<String>,
|
||||||
length: usize,
|
length: usize,
|
||||||
line_index: Arc<LineIndex>,
|
line_index: Arc<LineIndex>,
|
||||||
|
@ -167,9 +169,10 @@ struct AssetDocumentInner {
|
||||||
pub struct AssetDocument(Arc<AssetDocumentInner>);
|
pub struct AssetDocument(Arc<AssetDocumentInner>);
|
||||||
|
|
||||||
impl AssetDocument {
|
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();
|
let text = text.as_ref();
|
||||||
Self(Arc::new(AssetDocumentInner {
|
Self(Arc::new(AssetDocumentInner {
|
||||||
|
specifier,
|
||||||
text: Arc::new(text.to_string()),
|
text: Arc::new(text.to_string()),
|
||||||
length: text.encode_utf16().count(),
|
length: text.encode_utf16().count(),
|
||||||
line_index: Arc::new(LineIndex::new(text)),
|
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(
|
pub fn with_navigation_tree(
|
||||||
&self,
|
&self,
|
||||||
tree: Arc<NavigationTree>,
|
tree: Arc<NavigationTree>,
|
||||||
|
@ -216,7 +223,7 @@ fn new_assets_map() -> Arc<Mutex<AssetsMap>> {
|
||||||
.map(|(k, v)| {
|
.map(|(k, v)| {
|
||||||
let url_str = format!("asset:///{}", k);
|
let url_str = format!("asset:///{}", k);
|
||||||
let specifier = resolve_url(&url_str).unwrap();
|
let specifier = resolve_url(&url_str).unwrap();
|
||||||
let asset = AssetDocument::new(v);
|
let asset = AssetDocument::new(specifier.clone(), v);
|
||||||
(specifier, Some(asset))
|
(specifier, Some(asset))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -332,14 +339,15 @@ async fn get_asset(
|
||||||
) -> Result<Option<AssetDocument>, AnyError> {
|
) -> Result<Option<AssetDocument>, AnyError> {
|
||||||
let specifier_str = specifier.to_string().replace("asset:///", "");
|
let specifier_str = specifier.to_string().replace("asset:///", "");
|
||||||
if let Some(text) = tsc::get_asset(&specifier_str) {
|
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)
|
Ok(maybe_asset)
|
||||||
} else {
|
} else {
|
||||||
let res = ts_server
|
let res = ts_server
|
||||||
.request(state_snapshot, RequestMethod::GetAsset(specifier.clone()))
|
.request(state_snapshot, RequestMethod::GetAsset(specifier.clone()))
|
||||||
.await?;
|
.await?;
|
||||||
let maybe_text: Option<String> = serde_json::from_value(res)?;
|
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)
|
Ok(maybe_asset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1420,6 +1428,7 @@ pub struct Classifications {
|
||||||
impl Classifications {
|
impl Classifications {
|
||||||
pub fn to_semantic_tokens(
|
pub fn to_semantic_tokens(
|
||||||
&self,
|
&self,
|
||||||
|
asset_or_doc: &AssetOrDocument,
|
||||||
line_index: Arc<LineIndex>,
|
line_index: Arc<LineIndex>,
|
||||||
) -> LspResult<lsp::SemanticTokens> {
|
) -> LspResult<lsp::SemanticTokens> {
|
||||||
let token_count = self.spans.len() / 3;
|
let token_count = self.spans.len() / 3;
|
||||||
|
@ -1452,7 +1461,9 @@ impl Classifications {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
log::error!(
|
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,
|
start_pos,
|
||||||
end_pos
|
end_pos
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue