Skip to content

Commit e940feb

Browse files
authored
Code Action Tag for LLMs (#401)
Updates to latest LSP spec that contains CodeActionTag feature.
1 parent 7851838 commit e940feb

7 files changed

Lines changed: 491 additions & 27 deletions

File tree

generator/__main__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ def get_parser() -> argparse.ArgumentParser:
6161
return parser
6262

6363

64+
def custom_plugin(plugin: str) -> None:
65+
LOGGER.info(f"Loading plugin: {plugin}.")
66+
try:
67+
plugin_module = importlib.import_module(plugin)
68+
except ImportError:
69+
LOGGER.info(f"Loading plugin: generator.plugins.{plugin}.")
70+
plugin_module = importlib.import_module(f"generator.plugins.{plugin}")
71+
return plugin_module
72+
73+
6474
def main(argv: Sequence[str]) -> None:
6575
parser = get_parser()
6676
args = parser.parse_args(argv)
@@ -95,8 +105,7 @@ def main(argv: Sequence[str]) -> None:
95105
spec: model.LSPModel = model.create_lsp_model(json_models)
96106

97107
try:
98-
LOGGER.info(f"Loading plugin: {plugin}.")
99-
plugin_module = importlib.import_module(f"generator.plugins.{plugin}")
108+
plugin_module = custom_plugin(plugin)
100109
LOGGER.info(f"Running plugin: {plugin}.")
101110
plugin_module.generate(spec, output_dir, test_dir)
102111
LOGGER.info(f"Plugin {plugin} completed.")

generator/lsp.json

Lines changed: 127 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5168,9 +5168,19 @@
51685168
"name": "CompletionItemDefaults"
51695169
},
51705170
"optional": true,
5171-
"documentation": "In many cases the items of an actual completion result share the same\nvalue for properties like `commitCharacters` or the range of a text\nedit. A completion list can therefore define item defaults which will\nbe used if a completion item itself doesn't specify the value.\n\nIf a completion list specifies a default value and a completion item\nalso specifies a corresponding value the one from the item is used.\n\nServers are only allowed to return default values if the client\nsignals support for this via the `completionList.itemDefaults`\ncapability.\n\n@since 3.17.0",
5171+
"documentation": "In many cases the items of an actual completion result share the same\nvalue for properties like `commitCharacters` or the range of a text\nedit. A completion list can therefore define item defaults which will\nbe used if a completion item itself doesn't specify the value.\n\nIf a completion list specifies a default value and a completion item\nalso specifies a corresponding value, the rules for combining these are\ndefined by `applyKinds` (if the client supports it), defaulting to\n\"replace\".\n\nServers are only allowed to return default values if the client\nsignals support for this via the `completionList.itemDefaults`\ncapability.\n\n@since 3.17.0",
51725172
"since": "3.17.0"
51735173
},
5174+
{
5175+
"name": "applyKind",
5176+
"type": {
5177+
"kind": "reference",
5178+
"name": "CompletionItemApplyKinds"
5179+
},
5180+
"optional": true,
5181+
"documentation": "Specifies how fields from a completion item should be combined with those\nfrom `completionList.itemDefaults`.\n\nIf unspecified, all fields will be treated as \"replace\".\n\nIf a field's value is \"replace\", the value from a completion item (if\nprovided and not `null`) will always be used instead of the value from\n`completionItem.itemDefaults`.\n\nIf a field's value is \"merge\", the values will be merged using the rules\ndefined against each field below.\n\nServers are only allowed to return `applyKind` if the client\nsignals support for this via the `completionList.applyKindSupport`\ncapability.\n\n@since 3.18.0",
5182+
"since": "3.18.0"
5183+
},
51745184
{
51755185
"name": "items",
51765186
"type": {
@@ -5812,6 +5822,19 @@
58125822
"optional": true,
58135823
"documentation": "A data entry field that is preserved on a code action between\na `textDocument/codeAction` and a `codeAction/resolve` request.\n\n@since 3.16.0",
58145824
"since": "3.16.0"
5825+
},
5826+
{
5827+
"name": "tags",
5828+
"type": {
5829+
"kind": "array",
5830+
"element": {
5831+
"kind": "reference",
5832+
"name": "CodeActionTag"
5833+
}
5834+
},
5835+
"optional": true,
5836+
"documentation": "Tags for this code action.\n\n@since 3.18.0 - proposed",
5837+
"since": "3.18.0 - proposed"
58155838
}
58165839
],
58175840
"documentation": "A code action represents a change that can be performed in code, e.g. to fix a problem or\nto refactor code.\n\nA CodeAction must set either `edit` and/or a `command`. If both are supplied, the `edit` is applied first, then the `command` is executed."
@@ -9182,9 +9205,36 @@
91829205
"since": "3.17.0"
91839206
}
91849207
],
9185-
"documentation": "In many cases the items of an actual completion result share the same\nvalue for properties like `commitCharacters` or the range of a text\nedit. A completion list can therefore define item defaults which will\nbe used if a completion item itself doesn't specify the value.\n\nIf a completion list specifies a default value and a completion item\nalso specifies a corresponding value the one from the item is used.\n\nServers are only allowed to return default values if the client\nsignals support for this via the `completionList.itemDefaults`\ncapability.\n\n@since 3.17.0",
9208+
"documentation": "In many cases the items of an actual completion result share the same\nvalue for properties like `commitCharacters` or the range of a text\nedit. A completion list can therefore define item defaults which will\nbe used if a completion item itself doesn't specify the value.\n\nIf a completion list specifies a default value and a completion item\nalso specifies a corresponding value, the rules for combining these are\ndefined by `applyKinds` (if the client supports it), defaulting to\n\"replace\".\n\nServers are only allowed to return default values if the client\nsignals support for this via the `completionList.itemDefaults`\ncapability.\n\n@since 3.17.0",
91869209
"since": "3.17.0"
91879210
},
9211+
{
9212+
"name": "CompletionItemApplyKinds",
9213+
"properties": [
9214+
{
9215+
"name": "commitCharacters",
9216+
"type": {
9217+
"kind": "reference",
9218+
"name": "ApplyKind"
9219+
},
9220+
"optional": true,
9221+
"documentation": "Specifies whether commitCharacters on a completion will replace or be\nmerged with those in `completionList.itemDefaults.commitCharacters`.\n\nIf \"replace\", the commit characters from the completion item will\nalways be used unless not provided, in which case those from\n`completionList.itemDefaults.commitCharacters` will be used. An\nempty list can be used if a completion item does not have any commit\ncharacters and also should not use those from\n`completionList.itemDefaults.commitCharacters`.\n\nIf \"merge\" the commitCharacters for the completion will be the union\nof all values in both `completionList.itemDefaults.commitCharacters`\nand the completion's own `commitCharacters`.\n\n@since 3.18.0",
9222+
"since": "3.18.0"
9223+
},
9224+
{
9225+
"name": "data",
9226+
"type": {
9227+
"kind": "reference",
9228+
"name": "ApplyKind"
9229+
},
9230+
"optional": true,
9231+
"documentation": "Specifies whether the `data` field on a completion will replace or\nbe merged with data from `completionList.itemDefaults.data`.\n\nIf \"replace\", the data from the completion item will be used if\nprovided (and not `null`), otherwise\n`completionList.itemDefaults.data` will be used. An empty object can\nbe used if a completion item does not have any data but also should\nnot use the value from `completionList.itemDefaults.data`.\n\nIf \"merge\", a shallow merge will be performed between\n`completionList.itemDefaults.data` and the completion's own data\nusing the following rules:\n\n- If a completion's `data` field is not provided (or `null`), the\n entire `data` field from `completionList.itemDefaults.data` will be\n used as-is.\n- If a completion's `data` field is provided, each field will\n overwrite the field of the same name in\n `completionList.itemDefaults.data` but no merging of nested fields\n within that value will occur.\n\n@since 3.18.0",
9232+
"since": "3.18.0"
9233+
}
9234+
],
9235+
"documentation": "Specifies how fields from a completion item should be combined with those\nfrom `completionList.itemDefaults`.\n\nIf unspecified, all fields will be treated as \"replace\".\n\nIf a field's value is \"replace\", the value from a completion item (if\nprovided and not `null`) will always be used instead of the value from\n`completionItem.itemDefaults`.\n\nIf a field's value is \"merge\", the values will be merged using the rules\ndefined against each field below.\n\nServers are only allowed to return `applyKind` if the client\nsignals support for this via the `completionList.applyKindSupport`\ncapability.\n\n@since 3.18.0",
9236+
"since": "3.18.0"
9237+
},
91889238
{
91899239
"name": "CompletionOptions",
91909240
"properties": [
@@ -12681,6 +12731,16 @@
1268112731
"documentation": "Whether the client supports documentation for a class of\ncode actions.\n\n@since 3.18.0\n@proposed",
1268212732
"since": "3.18.0",
1268312733
"proposed": true
12734+
},
12735+
{
12736+
"name": "tagSupport",
12737+
"type": {
12738+
"kind": "reference",
12739+
"name": "CodeActionTagOptions"
12740+
},
12741+
"optional": true,
12742+
"documentation": "Client supports the tag property on a code action. Clients\nsupporting tags have to handle unknown tags gracefully.\n\n@since 3.18.0 - proposed",
12743+
"since": "3.18.0 - proposed"
1268412744
}
1268512745
],
1268612746
"documentation": "The Client Capabilities of a {@link CodeActionRequest}."
@@ -13537,6 +13597,16 @@
1353713597
"optional": true,
1353813598
"documentation": "The client supports the following itemDefaults on\na completion list.\n\nThe value lists the supported property names of the\n`CompletionList.itemDefaults` object. If omitted\nno properties are supported.\n\n@since 3.17.0",
1353913599
"since": "3.17.0"
13600+
},
13601+
{
13602+
"name": "applyKindSupport",
13603+
"type": {
13604+
"kind": "base",
13605+
"name": "boolean"
13606+
},
13607+
"optional": true,
13608+
"documentation": "Specifies whether the client supports `CompletionList.applyKind` to\nindicate how supported values from `completionList.itemDefaults`\nand `completion` will be combined.\n\nIf a client supports `applyKind` it must support it for all fields\nthat it supports that are listed in `CompletionList.applyKind`. This\nmeans when clients add support for new/future fields in completion\nitems the MUST also support merge for them if those fields are\ndefined in `CompletionList.applyKind`.\n\n@since 3.18.0",
13609+
"since": "3.18.0"
1354013610
}
1354113611
],
1354213612
"documentation": "The client supports the following `CompletionList` specific\ncapabilities.\n\n@since 3.17.0",
@@ -13624,6 +13694,24 @@
1362413694
"documentation": "@since 3.18.0",
1362513695
"since": "3.18.0"
1362613696
},
13697+
{
13698+
"name": "CodeActionTagOptions",
13699+
"properties": [
13700+
{
13701+
"name": "valueSet",
13702+
"type": {
13703+
"kind": "array",
13704+
"element": {
13705+
"kind": "reference",
13706+
"name": "CodeActionTag"
13707+
}
13708+
},
13709+
"documentation": "The tags supported by the client."
13710+
}
13711+
],
13712+
"documentation": "@since 3.18.0 - proposed",
13713+
"since": "3.18.0 - proposed"
13714+
},
1362713715
{
1362813716
"name": "ClientCodeLensResolveOptions",
1362913717
"properties": [
@@ -14772,6 +14860,22 @@
1477214860
"supportsCustomValues": true,
1477314861
"documentation": "A set of predefined code action kinds"
1477414862
},
14863+
{
14864+
"name": "CodeActionTag",
14865+
"type": {
14866+
"kind": "base",
14867+
"name": "uinteger"
14868+
},
14869+
"values": [
14870+
{
14871+
"name": "LLMGenerated",
14872+
"value": 1,
14873+
"documentation": "Marks the code action as LLM-generated."
14874+
}
14875+
],
14876+
"documentation": "Code action tags are extra annotations that tweak the behavior of a code action.\n\n@since 3.18.0 - proposed",
14877+
"since": "3.18.0 - proposed"
14878+
},
1477514879
{
1477614880
"name": "TraceValue",
1477714881
"type": {
@@ -15257,6 +15361,27 @@
1525715361
],
1525815362
"documentation": "How a completion was triggered"
1525915363
},
15364+
{
15365+
"name": "ApplyKind",
15366+
"type": {
15367+
"kind": "base",
15368+
"name": "string"
15369+
},
15370+
"values": [
15371+
{
15372+
"name": "Replace",
15373+
"value": "replace",
15374+
"documentation": "The value from the individual item (if provided and not `null`) will be\nused instead of the default."
15375+
},
15376+
{
15377+
"name": "Merge",
15378+
"value": "merge",
15379+
"documentation": "The value from the item will be merged with the default.\n\nThe specific rules for mergeing values are defined against each field\nthat supports merging."
15380+
}
15381+
],
15382+
"documentation": "Defines how values from a set of defaults and an individual item will be\nmerged.\n\n@since 3.18.0",
15383+
"since": "3.18.0"
15384+
},
1526015385
{
1526115386
"name": "SignatureHelpTriggerKind",
1526215387
"type": {

0 commit comments

Comments
 (0)