Skip to content

Commit

Permalink
fix: don't report diagnostics on remote modules (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Nov 30, 2023
1 parent b672348 commit 492fcd3
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ impl<'a> DiagnosticDocNodeVisitor<'a> {
pub fn visit_doc_nodes(&mut self, doc_nodes: &[DocNode]) {
let mut last_node: Option<&DocNode> = None;
for doc_node in doc_nodes {
if !doc_node.location.filename.starts_with("file:") {
continue; // don't report diagnostics on remote modules
}

if let Some(last_node) = last_node {
if doc_node.name == last_node.name && last_node.function_def.is_some() {
if let Some(current_fn) = &doc_node.function_def {
Expand Down
3 changes: 3 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,9 @@ impl<'a> DocParser<'a> {
let Some(diagnostics) = &self.diagnostics else {
return;
};
if doc_module_info.specifier().scheme() != "file" {
return; // don't report diagnostics on remote modules
}
let doc_symbol_id = doc_symbol.unique_id();
let Some(deps_by_member) =
self.visibility.get_root_exported_deps(&doc_symbol_id)
Expand Down
1 change: 1 addition & 0 deletions tests/specs/ModuleDocs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/** One associated with a class */
export class A {}

# output.txt
Defined in file:///mod.ts:3:1

Expand Down
175 changes: 175 additions & 0 deletions tests/specs/RemoteModuleReExportNoDiagnostics.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# mod.ts
export * from "https://localhost/mod.ts";
export * from "http://localhost/mod.ts";

# https://localhost/mod.ts
export function myFunction() {
return Math.random();
}

export class PublicType {
prop: NonExportedType;
}

class NonExportedType {
}

# http://localhost/mod.ts
export function myFunction2() {
return Math.random();
}

export class PublicType2 {
prop: NonExportedType2;
}

class NonExportedType2 {
}

# output.txt
Defined in https://localhost/mod.ts:1:1

function myFunction()

Defined in http://localhost/mod.ts:1:1

function myFunction2()

Defined in https://localhost/mod.ts:5:1

class PublicType

prop: NonExportedType

Defined in http://localhost/mod.ts:5:1

class PublicType2

prop: NonExportedType2


# output.json
[
{
"kind": "function",
"name": "myFunction",
"location": {
"filename": "https://localhost/mod.ts",
"line": 1,
"col": 0
},
"declarationKind": "export",
"functionDef": {
"params": [],
"returnType": null,
"hasBody": true,
"isAsync": false,
"isGenerator": false,
"typeParams": []
}
},
{
"kind": "class",
"name": "PublicType",
"location": {
"filename": "https://localhost/mod.ts",
"line": 5,
"col": 0
},
"declarationKind": "export",
"classDef": {
"isAbstract": false,
"constructors": [],
"properties": [
{
"tsType": {
"repr": "NonExportedType",
"kind": "typeRef",
"typeRef": {
"typeParams": null,
"typeName": "NonExportedType"
}
},
"readonly": false,
"accessibility": null,
"optional": false,
"isAbstract": false,
"isStatic": false,
"name": "prop",
"location": {
"filename": "https://localhost/mod.ts",
"line": 6,
"col": 2
}
}
],
"indexSignatures": [],
"methods": [],
"extends": null,
"implements": [],
"typeParams": [],
"superTypeParams": []
}
},
{
"kind": "function",
"name": "myFunction2",
"location": {
"filename": "http://localhost/mod.ts",
"line": 1,
"col": 0
},
"declarationKind": "export",
"functionDef": {
"params": [],
"returnType": null,
"hasBody": true,
"isAsync": false,
"isGenerator": false,
"typeParams": []
}
},
{
"kind": "class",
"name": "PublicType2",
"location": {
"filename": "http://localhost/mod.ts",
"line": 5,
"col": 0
},
"declarationKind": "export",
"classDef": {
"isAbstract": false,
"constructors": [],
"properties": [
{
"tsType": {
"repr": "NonExportedType2",
"kind": "typeRef",
"typeRef": {
"typeParams": null,
"typeName": "NonExportedType2"
}
},
"readonly": false,
"accessibility": null,
"optional": false,
"isAbstract": false,
"isStatic": false,
"name": "prop",
"location": {
"filename": "http://localhost/mod.ts",
"line": 6,
"col": 2
}
}
],
"indexSignatures": [],
"methods": [],
"extends": null,
"implements": [],
"typeParams": [],
"superTypeParams": []
}
}
]

0 comments on commit 492fcd3

Please sign in to comment.