-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multiple items in context triggering a warning #11
Conversation
Thanks to @AmjadHD for creating those schemas. |
schemas/sublime-project.json
Outdated
"type": "object" | ||
"type": "object", | ||
"properties": { | ||
"additionalProperties": false, |
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.
I don't agree with this decision to disallow additional properties. Various plugins out in the wild may use a sublime-project to store arbitrary data. Same goes for sublime-build files.
Disallowing additional properties in sublime-keymap, sublime-mousemap and sublime-completion files makes sense though.
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.
But plugins add those to settings
object, don't they? And settings
object allows additional properties.
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.
As for sublime-build
, do you have any examples where this is done currently?
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.
For sublime-build files, the value for the "target"
key is a WindowCommand
. It receives all key-value pairs of the invoked build target in **kwargs
.
For instance, I utilize this fact in my CMakeBuilder plugin to pass along build artefact information that I store in the ST build system.
For sublime-project files, you can get the entire content via window.project_data()
. It's a Python dictionary. You can put anything in there. And then you can store it with window.set_project_data(...)
. ST3 won't complain if there are unknown keys.
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.
For sublime-build files, the value for the
"target"
key is aWindowCommand
.
From the schema's perspective, it's a string though, no?
And target
is already in the schema:
LSP-json/schemas/sublime-build.json
Lines 47 to 50 in 2f72c1e
"target": { | |
"markdownDescription": "The command to run when the build system is invoked. The default value of exec allows use of the additional options specified in [exec Target Options](https://www.sublimetext.com/docs/3/build_systems.html#exec_options). If a value other than `exec` is specified, none of the options in exec Target Options will do anything. See the [Advanced Example](https://www.sublimetext.com/docs/3/build_systems.html#advanced_example) for a complete example.", | |
"type": "string" | |
}, |
For sublime-project files, you can get the entire content via
window.project_data()
. It's a Python dictionary.
Actually for sublime-project.json
, the additionalProperties
key is in the wrong place which makes it work as you would expect. It's defined inside properties
object which basically means that it defines a property called literally additionalProperties
rather than functioning as limiter. If it would be defined in the root of the schema then it would actually restrict properties that are allowed on the object.
So, it works as expected right now. I'll just remove that key.
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.
From the schema's perspective, it's a string though, no?
Ah, yes. I did not explain myself very well. You can have a build system like this:
{
"target": "make_thing",
"foo": "bar",
"selector": "source.python",
"some_number": 42
}
and define a command like this:
import sublime_plugin
class MakeThingCommand(sublime_plugin.WindowCommand):
def run(self, *args, **kwargs):
foo = kwargs.get("foo") # will have the value "bar"
selector = kwargs.get("selector") # will have the value "source.python"
some_number = kwargs.get("some_number") # will have the value 42
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 basically, ST does this: If "target"
is present, then invoke the corresponding command with the rest of the key-value pairs. Otherwise, invoke ExecCommand
with the rest of the key-value pairs.
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.
OK, I get it now. But in fact, sublime-build schema doesn't and never had additionalProperties: false
so I think we are good. :)
I have played around with this branch. Overall it's pretty cool, especially for keybindings. I hope we can add way more stuff, especially for things like color schemes and themes which will help tremendously. One thing that's annoying is that completions add two double-quotes at the beginning. When I type this (the {"k|"} I end up with this: {""keys": [|]"} This is understandable, as the completion item is: {
'label': 'keys',
'insertTextFormat': 2,
'insertText': '"keys": [$1]',
'textEdit':
{
'range':
{
'start': {'line': 17, 'character': 2},
'end': {'line': 17, 'character': 5}
},
'newText': '"keys": [$1]'
}
} What this textEdit says is to remove the Another thing I would suggest is to put |
It's time-consuming to create schemas but yes, we can do cool stuff with them. Even provide completions based on
Yes, the completion behavior is broken. I wonder if it has something to do with not respecting "completionProvider": {
"resolveProvider": false,
"triggerCharacters": [
"\"",
":"
]
}, from initialize. But in any case, I won't look into that unless new completions code still has problems with it. |
I am not sure about whether it's worth adding schemes for sublime-settings files for two reasons:
In a perfect world LSP-json would at least provide the ability to collect json schemes from all packages so authors can provide plugin-specific completion/tooltip infos. But in a real world anything else then something being created from sublime-settings files itself will always be out-dated. |
As far as completions and tooltips, I've created PR in PackageDev to add a setting to disable PackageDev's completions (and should also mention tooltips there). Then it would be user's choice what he prefers. Currently Also,
Yes, we've mentioned that in PR. And I agree that it would never be 100% complete if authors would have to opt-in into that so not sure if it's worth investing time in it. This package could also do what PackageDev is doing and create schemas dynamically from all discovered *.sublime-settings. It wouldn't be as complete as manually created schema but still useful. |
- Add $schema to all schemas and unify whitespace - Remove `additionalProperties: false` from sublime-project schema because: a) we don't actually want to limit keys to only known names b) it was defined in the wrong spot so it didn't function as one would expect (it was just an extra property called literally `additionalProperties`). - Add enum descriptions in sublime-settings schema - Use markdown for rendering descriptions - Added schema definitions created by AmjadHD Original schemas from https://github.com/AmjadHD/sublime_json_schemas - Fix multiple items in context triggering a warning If there was more than one object in context array, and those didn't follow the same schema then warning was triggered.
f2a6ab4
to
3617e0d
Compare
Interesting idea. Basically agree with the other arguments - lsp may be more powerful especially in long term with regards to object/array-like values such as the We'd just need a good tooling in order to create markdown descriptions. Writing such in a json file is just horrible. |
Actually it seems to be a bit random. Timing specific probably. |
If there was more than one object in context array, and those didn't
follow the same schema then warning was triggered.