Fix on_sheet_opened called twice from uri_handler#2914
Conversation
|
Isn't the right solution to just remove it from Line 1572 in 9c689cc Then it would get called a single time in all cases, no? |
No, due to fact that then this code will call The example case is: uri handler gets an URI with a fragment. The fragment declares position in the file so it's meant to be stripped from the uri before its set as But then I also think it's a bit rushed fix and ideally the |
But perhaps that's not that important because if you are opening a View then likely you want to use |
|
I think at Line 1465 in 828a94d uri that is passed into _on_sheet_opened. Possibly we might also want to normalize the URI at Line 1567 in 828a94d file: URIs).
And I think using the original |
|
Actually setting |
That would work for my use case. LSP-yaml supports inline hints that when clicked open schema for the corresponding yaml file. In that case it triggers opening of URI like: where the fragment is the URL to download the schema from. In that case we want to remove the fragment and use and LSP will handle those automatically to support jumping to specified location. But if that wouldn't work for |
|
In the Tinymist use case the server should better just use regular I think I would prefer setting the URI without fragment from |
But then there is the second issue of it being called twice if handler uses Or if we remove |
This reverts commit 5d89825.
The purpose for |
✅ Deploy Preview for sublime-lsp ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Not always, LSP-json wants to handle custom That said, I've realized that just returning We could try to make other discussed changes but not sure if needed and that we've arrived at perfect solution. |
|
I would even modify Then the example in the URI handler for the docs would be return session.open_scratch_buffer(...).then(lambda view: view.sheet()) |
|
Still doesn't feel optimal to me. I would expect |
Made title required and changed return type. |
|
To be honest, I still don't like it. We would also need to update the docstring: "Return a Promise resolved with the opened sheet if you opened the URI as an editor tab. Unless you used this particular function, then return Promise[None] for some internal reasons that we don't tell you here ¯\(ツ)/¯" The reason for having the sheet/view returned is that the function that called |
| ) -> Promise[sublime.View | None] | None: | ||
| # I cannot type-hint an unpacked tuple | ||
| pair: PackagedTask[tuple[str | None, str, str]] = Promise.packaged_task() | ||
| pair: PackagedTask[tuple[str, str, str]] = Promise.packaged_task() | ||
| promise, resolve = pair | ||
| # It'd be nice to have automatic tuple unpacking continuations | ||
| callback = lambda a, b, c: pair[1]((a, b, c)) # noqa: E731 | ||
| callback = lambda a, b, c: resolve((a or 'untitled', b, c)) # noqa: E731 | ||
| if plugin.on_open_uri_async(uri, callback): | ||
| result: PackagedTask[sublime.View | None] = Promise.packaged_task() | ||
| pair[0].then(lambda tup: self.open_scratch_buffer(*tup, uri, r, flags, group)).then(result[1]) | ||
| return result[0] | ||
| return promise.then(lambda tup: self.open_scratch_buffer(*tup, flags, group)) \ | ||
| .then(lambda view: self._on_sheet_opened(view.sheet(), uri, r)) | ||
| return None |
There was a problem hiding this comment.
Two PackagedTask's were unnecessary - one is enough.
This is a bit rushed fix so might need to have another, more thorough, look.
Problem:
When following the migration guide and using
session.open_scratch_buffer, the_on_sheet_openedwas called two times. Once with theuriprovided by the handler and then overridden with the originaluri.Remove the
_on_sheet_openedcall chained to the handler - if handler usessession.open_scratch_bufferthen it is not needed. When handler doesn't usesession.open_scratch_bufferthen this might be problematic to not call it though...(Another issue is that when following the migration guide the types are not validating because
session.open_scratch_bufferreturnsViewwhileuri_handlerwantssheetso there is extrathenneeded to convert the return value.)