templates/ident: improve "Identifier not used" message

"Identifier not used" is weird, replace it by "unknown identifier" and
 give the search identifier name in the header.

Also improve the autocomplete comment. Make it human-friendly and
explain why people got autocompleted to a symbol that does not exist.
Also, only show it if the symbol actually exists. That way we only
tell "maybe autocomplete lead you here" only in cases where
autocomplete can actually lead you here.

To test this feature:
 - search for any random symbol, you'll see "Unknown identifier '...'"
 - search for a symbol that exists in another version as the selected
   one. For example __NR_epoll_pwait2 appeared in musl v1.2.5. You'll
   see the same header message plus a comment about how the symbol
   exists in another version.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
This commit is contained in:
Théo Lebrun 2025-11-05 09:58:56 +01:00 committed by tleb
parent 1b24366093
commit e1bdface0c
5 changed files with 20 additions and 13 deletions

View file

@ -46,7 +46,7 @@ class ApiIdentGetterResource:
if version == 'latest':
version = query.get_latest_tag()
symbol_definitions, symbol_references, symbol_doccomments = query.search_ident(version, ident, family)
symbol_definitions, symbol_references, symbol_doccomments, _ = query.search_ident(version, ident, family)
resp.status = falcon.HTTP_200
resp.content_type = falcon.MEDIA_JSON

View file

@ -212,7 +212,7 @@ class Query:
ident = parse.quote(ident)
if not self.dts_comp_support or not self.db.comps.exists(ident):
return symbol_c, symbol_dts, symbol_docs
return symbol_c, symbol_dts, symbol_docs, False
files_this_version = self.db.vers.get(version).iter()
comps = self.db.comps.get(ident).iter(dummy=True)
@ -253,7 +253,7 @@ class Query:
for path, blines in sorted(compsBBuf):
symbol_docs.append(SymbolInstance(path, blines))
return symbol_c, symbol_dts, symbol_docs
return symbol_c, symbol_dts, symbol_docs, True
def get_idents_defs(self, version, ident, family):
@ -262,10 +262,10 @@ class Query:
symbol_doccomments = []
if not self.db.defs.exists(ident):
return symbol_definitions, symbol_references, symbol_doccomments
return symbol_definitions, symbol_references, symbol_doccomments, False
if not self.db.vers.exists(version):
return symbol_definitions, symbol_references, symbol_doccomments
return symbol_definitions, symbol_references, symbol_doccomments, True
files_this_version = self.db.vers.get(version).iter()
this_ident = self.db.defs.get(ident)
@ -330,5 +330,5 @@ class Query:
for path, docline in sorted(docBuf):
symbol_doccomments.append(SymbolInstance(path, docline))
return symbol_definitions, symbol_references, symbol_doccomments
return symbol_definitions, symbol_references, symbol_doccomments, True

View file

@ -695,7 +695,8 @@ def generate_ident_page(ctx: RequestContext, q: Query,
status = falcon.HTTP_OK
source_base_url = get_source_base_url(project, version)
symbol_definitions, symbol_references, symbol_doccomments = q.search_ident(version, ident, family)
symbol_definitions, symbol_references, symbol_doccomments, symbol_exists = q.search_ident(
version, ident, family)
symbol_sections = []
if len(symbol_definitions) or len(symbol_references):
@ -734,9 +735,8 @@ def generate_ident_page(ctx: RequestContext, q: Query,
'message': 'No references found in the database',
})
else:
if ident != '':
status = falcon.HTTP_NOT_FOUND
elif ident != '':
status = falcon.HTTP_NOT_FOUND
get_url_with_new_version = lambda v: stringify_ident_path(project, v, family, ident)
@ -747,6 +747,8 @@ def generate_ident_page(ctx: RequestContext, q: Query,
'current_family': family,
'symbol_sections': symbol_sections,
'symbol_exists': symbol_exists,
}
template = ctx.jinja_env.get_template('ident.html')

View file

@ -57,8 +57,13 @@
{% endif %}
{% endfor %}
{% else %}
<h2>Identifier not used</h2>
<div id="error-details">Note: Autocomplete currently searches identifiers in all versions of the project.</div>
<h2>Unknown identifier '{{ searched_ident|e }}'</h2>
{% if symbol_exists %}
<div id="error-details">
The '{{ searched_ident|e }}' symbol is defined in another version.
Elixir cannot efficiently tell where.
</div>
{% endif %}
{% endif %}
</div>

View file

@ -16,7 +16,7 @@ def cmd_versions(q, **kwargs):
print(v)
def cmd_ident(q, version, ident, family, **kwargs):
symbol_definitions, symbol_references, symbol_doccomments = q.search_ident(version, ident, family)
symbol_definitions, symbol_references, symbol_doccomments, _ = q.search_ident(version, ident, family)
print("Symbol Definitions:")
for symbol_definition in symbol_definitions:
print(symbol_definition)