summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-03-02 16:06:38 -0500
committerGitHub <noreply@github.com>2022-03-03 08:06:38 +1100
commite8c47755bbde3d14b38fd51de70922b1773ef6ee (patch)
treec692371b0f5e78d3b2a4afbff3cab1b3ba25f833 /cli
parent9de5275030b294bdcc9950bc6fa05feb93a43953 (diff)
chore(lsp): log more for "unexpected positions" lsp error (#13815)
Ref #13657
Diffstat (limited to 'cli')
-rw-r--r--cli/lsp/documents.rs15
-rw-r--r--cli/lsp/language_server.rs4
-rw-r--r--cli/lsp/tsc.rs21
3 files changed, 31 insertions, 9 deletions
diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs
index cc320db46..13071157b 100644
--- a/cli/lsp/documents.rs
+++ b/cli/lsp/documents.rs
@@ -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(
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 973dcc293..f9dfce4d5 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -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 {
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index a0f2008a4..b849f44e9 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -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
);