mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Add warning for unused imports
This commit is contained in:
parent
729939ad93
commit
6a078ee075
13 changed files with 53 additions and 5 deletions
|
@ -27,6 +27,7 @@ from .gtk_menu import Menu, menu
|
|||
from .gtkbuilder_template import Template
|
||||
from .imports import GtkDirective, Import
|
||||
from .translation_domain import TranslationDomain
|
||||
from .types import TypeName
|
||||
|
||||
|
||||
class UI(AstNode):
|
||||
|
@ -121,6 +122,22 @@ class UI(AstNode):
|
|||
Range(pos, pos, self.group.text),
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def used_imports(self) -> T.Optional[T.Set[str]]:
|
||||
def _iter_recursive(node: AstNode):
|
||||
yield node
|
||||
for child in node.children:
|
||||
if isinstance(child, AstNode):
|
||||
yield from _iter_recursive(child)
|
||||
|
||||
result = set()
|
||||
for node in _iter_recursive(self):
|
||||
if isinstance(node, TypeName):
|
||||
ns = node.gir_ns
|
||||
if ns is not None:
|
||||
result.add(ns.name)
|
||||
return result
|
||||
|
||||
@context(ScopeCtx)
|
||||
def scope_ctx(self) -> ScopeCtx:
|
||||
return ScopeCtx(node=self)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue