-
Notifications
You must be signed in to change notification settings - Fork 6
Highlight #34
Changes from all commits
4b7f164
407d597
2c80121
ad17370
2d893d4
b770377
7877265
8543360
49c1690
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Highlight Range Request | ||
|
||
request command: `mcfunction/highlightRange` | ||
|
||
request flow: Server -> Client | ||
|
||
Information data: | ||
|
||
```ts | ||
{ | ||
scopes: [ | ||
{ | ||
line: number, | ||
scopes: string[] | ||
} | ||
]; | ||
} | ||
``` | ||
|
||
# Highlight Text Request | ||
|
||
request command: `mfunction/highlightText` | ||
|
||
request flow: Client -> Server -> Client | ||
|
||
Request data: | ||
|
||
```ts | ||
{ | ||
text: string[]; //Split lines | ||
} | ||
``` | ||
|
||
Response data: | ||
|
||
```ts | ||
{ | ||
scopes: [ | ||
{ | ||
line: number, | ||
scopes: string[] | ||
} | ||
]; | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## Some notes | ||
|
||
Make sure that the begin and end are relative to the start of the line | ||
|
||
You _generally_ should not have multiple of the same scopes inside one another (directly) | ||
|
||
## Rules | ||
|
||
- Arguments should have the surrounding scope `["argument", "parser name"]`. | ||
- Example: `summon ~ ~ ~ zombie` | ||
|
||
```ts | ||
{ | ||
end: 7, | ||
scopes: ["argument", "minecraft:block_pos"], | ||
start: 12 | ||
} | ||
``` | ||
|
||
- Scopes of multiple names should be separated by `-` | ||
- Example: in `say @e[name="foo",tag=bar]` there should be | ||
|
||
```ts | ||
{ | ||
end: 18, | ||
scopes: ["kvpair-separator", "separator"], | ||
start: 17 | ||
} | ||
``` | ||
|
||
## Various scopes | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number of scopes here seems very complicated. You might also want to see microsoft/language-server-protocol#124. Having read through the arguments there, I have realised that it's probably better if the server sends highlighting, because we can then send it for each line (This is only better for our server) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, we might want to only support a more simple highlighting method initially until microsoft/language-server-protocol#18 is resolved, which seems to be proceeding in microsoft/vscode-languageserver-node#367. We don't want to make a massively complex system which becomes deprecated in a few weeks. |
||
`"kvpair"`: A key-value pair, like `foo:bar` or `foo=bar` | ||
`"*x*-separator"`: A separator between same scopes, like `"kvpair-separator"` would be `,` for NBT | ||
`"*x*-*y*-separator"`: A separator between different scopes, like `"key-value-separator"` would be `:` for NBT | ||
`"argument"`: A command argument. This shouldn't be used anywhere else | ||
`"key"`: A key, like foo in `foo:bar` and `foo=bar` | ||
`"value"`: A value, like bar in `foo:bar` and `foo=bar` | ||
`"quote"`: A quote character, IE `"` | ||
`"separator"`: Should accompany `*x*-separator` and `*x*-*y*-separator*` | ||
`"*x*-start"`: Start of a value with characters as start and end markers (like `{` and `[`). An accompanying `"start"` should also exist | ||
`"*x*-end"`: Same as `"*x*-start"` | ||
`"punctuation"`: Should exist on all characters used as a separator or start/end | ||
`"string"`: If the scoped value is a string | ||
`"quoted"`: If the string is quoted | ||
`"unquoted"`: If the string is unquoted | ||
`"prefix"`: If the character is a prefix | ||
`"suffix"`: Same as `"prefix"` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { HighlightScope, SubAction } from "../types"; | ||
|
||
export function actionFromScopes(scopes: HighlightScope[]): SubAction[] { | ||
return scopes.map<SubAction>(actionFromScope); | ||
} | ||
|
||
export function actionFromScope(scope: HighlightScope): SubAction { | ||
return { | ||
data: scope.scopes, | ||
high: scope.end, | ||
low: scope.start, | ||
type: "highlight" | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { CompletionItemKind } from "vscode-languageserver"; | ||
import { ReturnHelper } from "../misc_functions"; | ||
import { actionFromScope, ReturnHelper } from "../misc_functions"; | ||
import { Parser } from "../types"; | ||
|
||
const parser: Parser = { | ||
|
@@ -19,6 +19,13 @@ const parser: Parser = { | |
if (reader.string.substring(begin, end) === literal) { | ||
reader.cursor = end; | ||
if (reader.peek() === " " || !reader.canRead()) { | ||
helper.addActions( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This being an action is actually quite awkward, because if there is ambiguity, then what should happen? Text can only be highlighted in one colour. Additionally, what about in the case of failures. Do we include the mangled scopes. What about if parsing one thing failed with some highlighting, but something else suceeded. How do we prioritise the values. |
||
actionFromScope({ | ||
end: reader.cursor, | ||
scopes: ["argument", "literal"], | ||
start: begin | ||
}) | ||
); | ||
return helper.succeed(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be updated to |
||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ describe("literalArgumentParser", () => { | |
defined(literalArgumentParser.parse(reader, properties)), | ||
true, | ||
[], | ||
["test"] | ||
["test"], | ||
1 | ||
); | ||
assert.strictEqual(reader.cursor, 4); | ||
}); | ||
|
@@ -28,10 +29,26 @@ describe("literalArgumentParser", () => { | |
defined(literalArgumentParser.parse(reader, properties)), | ||
true, | ||
[], | ||
[] | ||
[], | ||
1 | ||
); | ||
assert.strictEqual(reader.cursor, 4); | ||
}); | ||
it("should return the correct highlight data", () => { | ||
const reader = new StringReader("test"); | ||
const out = literalArgumentParser.parse(reader, properties); | ||
assert.deepStrictEqual( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we need a better way of managing testing actions: actions should be tested inside each test, not as a seperate test. Maybe an |
||
out.actions.filter(v => v.type === "highlight"), | ||
[ | ||
{ | ||
data: ["argument", "literal"], | ||
high: 4, | ||
low: 0, | ||
type: "highlight" | ||
} | ||
] | ||
); | ||
}); | ||
}); | ||
describe("literal not matching", () => { | ||
it("should fail when the first character doesn't match", () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when the client recieves this request, it should highlight each occurance of a line number in every open document in the correct colours for the scopes?
How does that make any sense?
Surely we need to send ranges with scopes