Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit 73d17e8

Browse files
author
jchapuis
committed
renamed kind to meta
1 parent 69bf965 commit 73d17e8

File tree

6 files changed

+48
-48
lines changed

6 files changed

+48
-48
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ Completing on the same expressions (`2`, `2+`, `(10*2`) now leads to the followi
228228
|`%` |defines the completions tag|<code>("+" &#124; "-") % "operators"</code>|
229229
|`%` |followed by an `Int`, defines the completion tag score|<code>("+" &#124; "-") % 10</code>|
230230
|`%?` |defines the description of the completions tag|<code>("+" &#124; "-") %? "arithmetic operators"</code>|
231-
|`%%` |defines the completions tag kind (can be used to encode properties for the tag, e.g. visual decorations)|<code>("+" &#124; "-") %% "style: highlight"</code>|
232-
|`%-%` |defines the completion kind (can be used to encode properties for each completion entry, e.g. visual decorations)|<code>("+" %-% "style: highlight" &#124; "-")</code>|
231+
|`%%` |defines the completions tag meta-data (can be used to encode properties for the tag, e.g. visual decorations)|<code>("+" &#124; "-") %% "style: highlight"</code>|
232+
|`%-%` |defines the completion meta-data (can be used to encode properties for each completion entry, e.g. visual decorations)|<code>("+" %-% "style: highlight" &#124; "-")</code>|
233233

234234
## Fuzzy completion
235235

src/main/scala/com/nexthink/utils/parsing/combinator/completion/CompletionExpansionSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ trait CompletionExpansionSupport extends RegexCompletionSupport {
6060
.map(c => {
6161
val completedInput = completeString(str, completions.position.column, c)
6262
if (stop(new CharSequenceReader(completedInput)).successful) {
63-
Completions(in.pos, CompletionSet(cSet.tag, Set(Completion(completedInput, c.score, c.kind))))
63+
Completions(in.pos, CompletionSet(cSet.tag, Set(Completion(completedInput, c.score, c.meta))))
6464
} else {
6565
exploreCompletionsRec(completedInput, p.completions(ExplorerReader(p, completedInput)))
6666
}

src/main/scala/com/nexthink/utils/parsing/combinator/completion/CompletionSupport.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import scala.language.implicitConversions
2929
* with `RegexParsers` to automatically obtain completion behavior for string literals.
3030
*
3131
* A set of additional operators allow defining completions and specifying structural properties of completions
32-
* (tag, score, kind, etc.) for a `Parser`.
32+
* (tag, score, meta, etc.) for a `Parser`.
3333
*
3434
* @author Jonas Chapuis
3535
*/
@@ -153,11 +153,11 @@ trait CompletionSupport extends Parsers with CompletionTypes {
153153
Parser(this,
154154
in => updateCompletionsTag(this.completions(in), Some(tag), Some(tagScore), Some(tagDescription), None))
155155

156-
/** An operator to specify the completion tag, score, description and kind of a parser
156+
/** An operator to specify the completion tag, score, description and meta of a parser
157157
* @param tag the completion tag
158158
* @param tagScore the completion tag score
159159
* @param tagDescription the completion tag description
160-
* @param tagKind the completion tag kind
160+
* @param tagKind the completion tag meta
161161
* @return wrapper `Parser` instance specifying completion tag
162162
*/
163163
def %(tag: String, tagScore: Int, tagDescription: String, tagKind: String): Parser[T] =
@@ -173,7 +173,7 @@ trait CompletionSupport extends Parsers with CompletionTypes {
173173
def %(tag: CompletionTag): Parser[T] =
174174
Parser(
175175
this,
176-
in => updateCompletionsTag(this.completions(in), Some(tag.label), Some(tag.score), tag.description, tag.kind))
176+
in => updateCompletionsTag(this.completions(in), Some(tag.label), Some(tag.score), tag.description, tag.meta))
177177

178178
/** An operator to specify the completion tag description of a parser (empty by default)
179179
* @param tagDescription the completion description (to be used e.g. to add information to a completion entry)
@@ -182,19 +182,19 @@ trait CompletionSupport extends Parsers with CompletionTypes {
182182
def %?(tagDescription: String): Parser[T] =
183183
Parser(this, in => updateCompletionsTag(this.completions(in), None, None, Some(tagDescription), None))
184184

185-
/** An operator to specify the completion tag kind of a parser (empty by default)
186-
* @param tagKind the completion tag kind (to be used e.g. to specify the visual style for a completion tag in the menu)
187-
* @return wrapper `Parser` instance specifying the completion tag kind
185+
/** An operator to specify the completion tag meta of a parser (empty by default)
186+
* @param tagMeta the completion tag meta-data (to be used e.g. to specify the visual style for a completion tag in the menu)
187+
* @return wrapper `Parser` instance specifying the completion tag meta-data
188188
*/
189-
def %%(tagKind: String): Parser[T] =
190-
Parser(this, in => updateCompletionsTag(this.completions(in), None, None, None, Some(tagKind)))
189+
def %%(tagMeta: String): Parser[T] =
190+
Parser(this, in => updateCompletionsTag(this.completions(in), None, None, None, Some(tagMeta)))
191191

192-
/** An operator to specify the kind for completions of a parser (empty by default)
193-
* @param kind the completion kind (to be used e.g. to specify the visual style for a completion entry in the menu)
194-
* @return wrapper `Parser` instance specifying the completion kind
192+
/** An operator to specify the meta for completions of a parser (empty by default)
193+
* @param meta the completion meta-data (to be used e.g. to specify the visual style for a completion entry in the menu)
194+
* @return wrapper `Parser` instance specifying the completion meta-data
195195
*/
196-
def %-%(kind: String): Parser[T] =
197-
Parser(this, in => updateCompletions(this.completions(in), Some(kind)))
196+
def %-%(meta: String): Parser[T] =
197+
Parser(this, in => updateCompletions(this.completions(in), Some(meta)))
198198

199199
def flatMap[U](f: T => Parser[U]): Parser[U] =
200200
Parser(super.flatMap(f), completions)

src/main/scala/com/nexthink/utils/parsing/combinator/completion/CompletionTypes.scala

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import org.json4s.native.JsonMethods._
1919
* `Completion` entries and is tagged with a `CompletionTag`.
2020
*
2121
* Sets allow structuring the completion entries into groups, each group tagged with a `label` (plus optional
22-
* `description` and `kind`, the latter allowing e.g. encoding visual attributes for the set).
22+
* `description` and `meta`, the latter allowing e.g. encoding visual attributes for the set).
2323
* Sets also feature a score, which defines the order between sets within the `Completions` instance.
2424
*
25-
* Each `Completion` entry within a set has a `value`, a `score` and a `kind`:
26-
* the score allows ordering the entries within a set, and the kind can e.g. be used to assign a representation style
25+
* Each `Completion` entry within a set has a `value`, a `score` and a `meta`:
26+
* the score allows ordering the entries within a set, and the meta can e.g. be used to assign a representation style
2727
* for a particular completion entry.
2828
*
2929
* Note that specifying tags and sets is optional: if no tag is specified upon creation,
@@ -41,19 +41,19 @@ trait CompletionTypes {
4141
* @param label tag label
4242
* @param score tag score (the higher the better, 0 by default)
4343
* @param description tag description (optional) - can be used for additional information e.g. for a tooltip
44-
* @param kind tag kind (optional) - can be used e.g. to define visual style
44+
* @param meta tag meta (optional) - can be used e.g. to define visual style
4545
*/
46-
case class CompletionTag(label: String, score: Int, description: Option[String], kind: Option[String]) {
47-
def update(newTag: Option[String], newScore: Option[Int], newDescription: Option[String], newKind: Option[String]): CompletionTag =
46+
case class CompletionTag(label: String, score: Int, description: Option[String], meta: Option[String]) {
47+
def update(newTag: Option[String], newScore: Option[Int], newDescription: Option[String], newMeta: Option[String]): CompletionTag =
4848
copy(
4949
label = newTag.getOrElse(label),
5050
score = newScore.getOrElse(score),
5151
description = newDescription.map(Some(_)).getOrElse(description),
52-
kind = newKind.map(Some(_)).getOrElse(kind)
52+
meta = newMeta.map(Some(_)).getOrElse(meta)
5353
)
5454

5555
private[CompletionTypes] def serializeJson: json4s.JObject = {
56-
("label" -> label) ~ ("score" -> score) ~ ("description" -> description) ~ ("kind" -> kind)
56+
("label" -> label) ~ ("score" -> score) ~ ("description" -> description) ~ ("meta" -> meta)
5757
}
5858

5959
override def toString: String = pretty(render(serializeJson))
@@ -77,7 +77,7 @@ trait CompletionTypes {
7777
def label: String = tag.label
7878
def score: Int = tag.score
7979
def description: Option[String] = tag.description
80-
def kind: Option[String] = tag.kind
80+
def meta: Option[String] = tag.meta
8181
def completionStrings: Seq[String] =
8282
completions.toSeq.sorted.map(_.value.toString)
8383

@@ -119,14 +119,14 @@ trait CompletionTypes {
119119
/** Completion entry
120120
* @param value entry value (e.g. string literal)
121121
* @param score entry score (defines the order of entries within a set, the higher the better)
122-
* @param kind entry kind (e.g. visual style)
122+
* @param meta entry meta (e.g. visual style)
123123
*/
124-
case class Completion(value: Elems, score: Int = DefaultCompletionScore, kind: Option[String] = None) {
124+
case class Completion(value: Elems, score: Int = DefaultCompletionScore, meta: Option[String] = None) {
125125
require(value.nonEmpty, "empty completion")
126-
def updateKind(newKind: Option[String]): Completion =
127-
copy(kind = newKind.map(Some(_)).getOrElse(kind))
126+
def updateKind(newMeta: Option[String]): Completion =
127+
copy(meta = newMeta.map(Some(_)).getOrElse(meta))
128128

129-
private[CompletionTypes] def serializeJson = ("value" -> value.toString()) ~ ("score" -> score) ~ ("kind" -> kind)
129+
private[CompletionTypes] def serializeJson = ("value" -> value.toString()) ~ ("score" -> score) ~ ("meta" -> meta)
130130

131131
def toJson: String = compact(render(serializeJson))
132132

@@ -160,11 +160,11 @@ trait CompletionTypes {
160160
val isOffsetRequired =
161161
set.completions.map(_.score).exists(_ < set.score)
162162
if (isOffsetRequired)
163-
set.completions.map(c => Completion(c.value, set.score + c.score, c.kind))
163+
set.completions.map(c => Completion(c.value, set.score + c.score, c.meta))
164164
else set.completions
165165
}
166166
CompletionSet(
167-
CompletionTag(left.tag.label, left.score.min(right.score), left.description, left.kind.orElse(right.kind)),
167+
CompletionTag(left.tag.label, left.score.min(right.score), left.description, left.meta.orElse(right.meta)),
168168
offsetCompletions(left) ++ offsetCompletions(right)
169169
)
170170
}
@@ -210,7 +210,7 @@ trait CompletionTypes {
210210
val sortedEntries =
211211
allEntries
212212
.sortBy {
213-
case (Completion(_, score, kind), CompletionTag(_, tagScore, _, _)) =>
213+
case (Completion(_, score, meta), CompletionTag(_, tagScore, _, _)) =>
214214
(tagScore, score)
215215
}
216216
.reverse

src/test/scala/com/nexthink/utils/parsing/combinator/completion/CompletionForIntoTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CompletionForIntoTest {
2020
object TestParser extends RegexParsers with RegexCompletionSupport {
2121
val animalParser = bear | lion
2222
val machineParser = "plane" | "car"
23-
val test = (animal | machine) >> { kind: String => if (kind == animal) animalParser else machineParser }
23+
val test = (animal | machine) >> { meta: String => if (meta == animal) animalParser else machineParser }
2424
}
2525

2626
@Test

src/test/scala/com/nexthink/utils/parsing/combinator/completion/CompletionOperatorsTest.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class CompletionOperatorsTest {
2323
val score = 10
2424
val description = "some description"
2525
val tag = "some tag"
26-
val kind = "some kind"
26+
val meta = "some meta"
2727

28-
assertCompletionsMatch(TestParser.someParser %> (completions: _*) % (tag, score) %? description %% kind,
28+
assertCompletionsMatch(TestParser.someParser %> (completions: _*) % (tag, score) %? description %% meta,
2929
completions,
3030
Some(tag),
3131
Some(score),
3232
Some(description),
33-
Some(kind))
33+
Some(meta))
3434

3535
assertCompletionsMatch(TestParser.someParser %> (completions: _*) % (tag, score, description),
3636
completions,
@@ -39,43 +39,43 @@ class CompletionOperatorsTest {
3939
Some(description),
4040
None)
4141

42-
assertCompletionsMatch(TestParser.someParser %> (completions: _*) % (tag, score, description, kind),
42+
assertCompletionsMatch(TestParser.someParser %> (completions: _*) % (tag, score, description, meta),
4343
completions,
4444
Some(tag),
4545
Some(score),
4646
Some(description),
47-
Some(kind))
47+
Some(meta))
4848

4949
assertCompletionsMatch(
50-
TestParser.someParser %> (completions: _*) % TestParser.CompletionTag(tag, score, Some(description), Some(kind)),
50+
TestParser.someParser %> (completions: _*) % TestParser.CompletionTag(tag, score, Some(description), Some(meta)),
5151
completions,
5252
Some(tag),
5353
Some(score),
5454
Some(description),
55-
Some(kind)
55+
Some(meta)
5656
)
5757

58-
assertCompletionsMatch(TestParser.someParser %> (completions: _*) % tag %? description % score %% kind,
58+
assertCompletionsMatch(TestParser.someParser %> (completions: _*) % tag %? description % score %% meta,
5959
completions,
6060
Some(tag),
6161
Some(score),
6262
Some(description),
63-
Some(kind))
63+
Some(meta))
6464

65-
assertCompletionsMatch(TestParser.someParser %> (completions: _*) % tag % score %? description %% kind,
65+
assertCompletionsMatch(TestParser.someParser %> (completions: _*) % tag % score %? description %% meta,
6666
completions,
6767
Some(tag),
6868
Some(score),
6969
Some(description),
70-
Some(kind))
70+
Some(meta))
7171
}
7272

7373
def assertCompletionsMatch[T](sut: TestParser.Parser[T],
7474
completions: Seq[Seq[Char]],
7575
tag: Option[String],
7676
score: Option[Int],
7777
description: Option[String],
78-
kind: Option[String]): Unit = {
78+
meta: Option[String]): Unit = {
7979
// Act
8080
val result = TestParser.complete(sut, "")
8181

@@ -85,7 +85,7 @@ class CompletionOperatorsTest {
8585
Assert.assertEquals(tag.getOrElse(""), completionSet.tag.label)
8686
Assert.assertEquals(score.getOrElse(0), completionSet.tag.score)
8787
Assert.assertEquals(description, completionSet.tag.description)
88-
Assert.assertEquals(kind, completionSet.tag.kind)
88+
Assert.assertEquals(meta, completionSet.tag.meta)
8989
Assert.assertEquals(completions.toSet, completionSet.completions.map(_.value))
9090
}
9191

0 commit comments

Comments
 (0)