Skip to content

Commit a06d00d

Browse files
committed
optimize hover std
1 parent 11d63dc commit a06d00d

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

crates/emmylua_ls/src/handlers/hover/hover_builder.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use emmylua_code_analysis::{
55
use emmylua_parser::{LuaAstNode, LuaCallExpr, LuaIndexExpr, LuaSyntaxKind, LuaSyntaxToken};
66
use lsp_types::{Hover, HoverContents, MarkedString, MarkupContent};
77

8-
use crate::handlers::hover::std_hover::{hover_std_description, is_std_by_name};
8+
use crate::handlers::hover::std_hover::hover_std_description;
99

1010
use super::{
1111
build_hover::{add_signature_param_description, add_signature_ret_description},
12-
std_hover::is_std_by_path,
12+
std_hover::is_std,
1313
};
1414

1515
#[derive(Debug)]
@@ -136,7 +136,7 @@ impl<'a> HoverBuilder<'a> {
136136
.get_member(&id)
137137
{
138138
if let LuaMemberOwner::Type(ty) = &member.get_owner() {
139-
if is_std_by_name(&ty.get_name()) {
139+
if is_std(self.semantic_model.get_db(), member.get_file_id()) {
140140
let std_desc = hover_std_description(
141141
ty.get_name(),
142142
member.get_key().get_name(),
@@ -151,11 +151,7 @@ impl<'a> HoverBuilder<'a> {
151151
LuaSemanticDeclId::LuaDecl(id) => {
152152
if let Some(decl) = self.semantic_model.get_db().get_decl_index().get_decl(&id)
153153
{
154-
if decl.is_global()
155-
&& is_std_by_name(&decl.get_name())
156-
&& is_std_by_path(self.semantic_model.get_db(), decl.get_file_id())
157-
.unwrap_or(false)
158-
{
154+
if is_std(self.semantic_model.get_db(), decl.get_file_id()) {
159155
let std_desc = hover_std_description(decl.get_name(), None);
160156
if !std_desc.is_empty() {
161157
description = std_desc;

crates/emmylua_ls/src/handlers/hover/std_hover.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use emmylua_code_analysis::{DbIndex, FileId};
22

33
use crate::meta_text::meta_std;
44

5+
#[allow(unused)]
56
pub fn is_std_by_name(name: &str) -> bool {
67
match name {
78
"oslib" => true,
@@ -57,7 +58,6 @@ pub fn hover_std_description(type_name: &str, member_name: Option<&str>) -> Stri
5758
meta_std(type_name, member_name)
5859
}
5960

60-
pub fn is_std_by_path(db: &DbIndex, file_id: FileId) -> Option<bool> {
61-
let module_info = db.get_module_index().get_module(file_id)?;
62-
Some(module_info.workspace_id.is_std())
61+
pub fn is_std(db: &DbIndex, file_id: FileId) -> bool {
62+
db.get_module_index().is_std(&file_id)
6363
}

0 commit comments

Comments
 (0)