Skip to content

Commit

Permalink
Static parameter in search/completion request affects only methods (#…
Browse files Browse the repository at this point in the history
…7831)

close #7805

Changelog:
update: `isStatic` parameter in the `search/completion` request only affects method suggestions
  • Loading branch information
4e6 authored Sep 19, 2023
1 parent e3de688 commit 5c19814
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/language-server/protocol-language-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -4636,7 +4636,7 @@ Sent from client to the server to receive the autocomplete suggestion.
returnType?: string;
// Filter by the suggestion types
tags?: [SuggestionEntryType];
// Filter by `static` attribute of the suggestion
// Filter by `static` attribute of method suggestions
isStatic?: Boolean;
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ class SuggestionsHandlerSpec
Suggestions.methodOnInteger
)

val (_, Seq(_, _, _, methodId, _, _, _, _, _)) =
val (_, Seq(moduleId, typeId, consId, methodId, _, localId, _, _, _)) =
Await.result(repo.insertAll(all), Timeout)
handler ! SearchProtocol.Completion(
file = mkModulePath(config, "Main.enso"),
Expand All @@ -910,7 +910,7 @@ class SuggestionsHandlerSpec
expectMsg(
SearchProtocol.CompletionResult(
1L,
Seq(methodId)
Seq(moduleId, typeId, consId, methodId, localId)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ final class SqlSuggestionsRepo(val db: SqlDatabase)(implicit
)
}
.filterOpt(isStatic) { case (row, value) =>
row.isStatic === value
(row.kind === SuggestionKind.METHOD && row.isStatic === value) ||
(row.kind =!= SuggestionKind.METHOD)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,13 +1160,14 @@ class SuggestionsRepoTest
"search suggestion by the static attribute" taggedAs Retry in withRepo {
repo =>
val action = for {
_ <- repo.insert(suggestion.module)
_ <- repo.insert(suggestion.tpe)
_ <- repo.insert(suggestion.constructor)
id0 <- repo.insert(suggestion.module)
id1 <- repo.insert(suggestion.tpe)
id2 <- repo.insert(suggestion.constructor)
id3 <- repo.insert(suggestion.method)
_ <- repo.insert(suggestion.conversion)
_ <- repo.insert(suggestion.function)
_ <- repo.insert(suggestion.local)
_ <- repo.insert(suggestion.instanceMethod)
id5 <- repo.insert(suggestion.conversion)
id6 <- repo.insert(suggestion.function)
id7 <- repo.insert(suggestion.local)
res <-
repo.search(
None,
Expand All @@ -1176,11 +1177,10 @@ class SuggestionsRepoTest
None,
Some(true)
)
} yield (id3, res._2)
} yield (Seq(id0, id1, id2, id3, id5, id6, id7), res._2)

val (id3, res) =
Await.result(action, Timeout)
res should contain theSameElementsAs Seq(id3).flatten
val (ids, res) = Await.result(action, Timeout)
res should contain theSameElementsAs ids.flatten
}

"search suggestion by module and self type" taggedAs Retry in withRepo {
Expand Down Expand Up @@ -1233,6 +1233,32 @@ class SuggestionsRepoTest
res should contain theSameElementsAs Seq(id3).flatten
}

"search suggestion by self-type and non-static attribute" taggedAs Retry in withRepo {
repo =>
val action = for {
_ <- repo.insert(suggestion.module)
_ <- repo.insert(suggestion.tpe)
_ <- repo.insert(suggestion.constructor)
_ <- repo.insert(suggestion.method)
id4 <- repo.insert(suggestion.instanceMethod)
_ <- repo.insert(suggestion.conversion)
_ <- repo.insert(suggestion.function)
_ <- repo.insert(suggestion.local)
res <-
repo.search(
None,
Seq(suggestion.instanceMethod.selfType),
None,
None,
None,
Some(false)
)
} yield (Seq(id4), res._2)

val (ids, res) = Await.result(action, Timeout)
res should contain theSameElementsAs ids.flatten
}

"search suggestion by return type and kind" taggedAs Retry in withRepo {
repo =>
val kinds = Seq(Suggestion.Kind.Constructor, Suggestion.Kind.Local)
Expand Down

0 comments on commit 5c19814

Please sign in to comment.