-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat: add ability to create custom editors for files #229
Conversation
3b70c7f
to
7be06d1
Compare
7be06d1
to
c99b6f3
Compare
Can you please fix the eslint warning and the demo? |
c99b6f3
to
66e6972
Compare
a little bit complex indeed :) What about adding the Also can you demonstrate it in the demo? |
The user would lose some customisability (e.g. can't pass editor options, or define how the untitled editor should launch). But at the same time, it would make the API more accessible. I can add it as an optional parameter. If people then don't pass it they still have the opportunity to register it in a custom way themselves 😄. |
Yep, it looks like a good compromise |
66e6972
to
dca83aa
Compare
How can I get access to the |
StandaloneServices.get is fine. You just need to make sure the services are initialized, either by wrapping it into a |
Okay, will apply the changes in about ~45min! |
TIC TAC TIC TAC 😄 |
On it! 😂 |
dca83aa
to
7f670f9
Compare
Okay, updated, but I can't get the demo running, so will need to double check that. |
What is the error? |
7f670f9
to
e70db06
Compare
Got it fixed! Had to reinstall |
b679c35
to
61523b8
Compare
Okay, this change is not working yet. Because Monaco triggers |
Or... No, our |
Not sure to follow, what is the solution? maybe you can use |
Ah, |
61523b8
to
12266db
Compare
Okay, confirmed that with this push everything is working! |
12266db
to
ae55167
Compare
There is still a few comments from me you didn't address :) |
Ah, hmm. So for these comments:
The
The existing custom editor is now also opened for Are there some other comments that I missed? |
Oh they're still on "Pending"! So I can't see them yet, I'll work on them from the screenshot. |
ae55167
to
f86ca0b
Compare
Addressed the feedback! |
Ok totally my bad... sorry, I'm more used to gitlab than github |
f86ca0b
to
48557cd
Compare
Okay, addressed the remaining feedback |
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 just tried to play with the feature, that's a nice addition, I just have a few suggestions to improve it :)
I like these suggestions. I have a call right now, will go through them in 30min and apply them one by one. |
48557cd
to
c8b096f
Compare
Made some changes to the API! This API is much better, I like the suggestion. |
5cc0fe8
to
90872a1
Compare
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'm sorry to have so many concerns, but that MR is a little tricky and it impacts the public API of the library. I'd like it to be as nice as possible because it's better to not change it afterward
@@ -197,7 +203,7 @@ type Label = string | { | |||
interface EditorPanelOption { | |||
readonly id: string | |||
name: string | |||
renderBody (container: HTMLElement): IDisposable | |||
renderBody (container: HTMLElement): BodyRenderer |
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'm not really happy with extending IDisposable here
an alternative that is used a lot inside VSCode itself is to provide a DisposableStore as the last parameter
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.
The risk I see with that is that it's easy to forget for the consumer. If they forget to handle that parameter, then it won't get disposed. Now the type system will give an error if dispose()
is not implemented on the returned value, making sure that things get cleaned up when we get rid of them.
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.
The dispose function being mandatory in on the cons
column for me 😄 most of the time, you don't need it (for instance if you render a react component using portal?)
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.
In our React case we do need to handle dispose, because when dispose is called we need to remove the component from our list. Otherwise the component will try to render on an element that is not attached to the DOM anymore. In React we also need to run the disposers of useEffect
during that moment.
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.
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 a last point, I think that this can feel like VSCode, with how they often use classes for UI. E.g. you could also pass this to it:
class MarkdownRenderer extends Disposable {
constructor() { }
setInput(input) {
this.draw();
}
private draw() { /* ... */ }
}
Will put the changes in today! |
90872a1
to
c816018
Compare
Addressed the feedback and pushed it. Only thing I haven't addressed is the disposable. I would still prefer that disposing is opt-out, instead of opt-in. Otherwise we create a footgun where users can have lingering resources that never get cleaned up even though the editor gets disposed. |
c816018
to
362fd0a
Compare
There is many concerns and questions on how to create an api that is simple enough but still allows the user to do as much as possible... That equation is complicated here. I've realized the VSCode api allows to do a lot more than what I initialy though and I vote for refactoring it to be as close as possible to the way it's used inside VSCode itself The result can be something like #239 What do you think? Pros:
cons:
|
Quick check on the PR, and I love it. More power to the implementor. I will check more thoroughly in 30min. |
Okay, I like the PR! It's a good approach, and from what I can see so far, it will also work for our case. I particularly like that the tab title can stay consistent.
Agree, the closer to VSCode the better. People can always build a simple wrapper around it (probably we'll do this to make it work with React properly)
Will check this, I think that should also be fine on our side! |
Yep, works here! |
This PR is a bit more tricky. I've been looking into ways that we can render custom editors for files. Our specific use case is rendering a custom interactive Markdown for markdown files, and we've been wanting to use React for this as it's more integrated with our editor.
While there's currently a nice API for creating custom editors, it does not handle creating custom editors for files yet. The missing piece to enable this is the
IEditorResolverService
, you can register a custom editor like so:This works really well, but the last missing piece is that VSCode will call
setInput
on the editor to set the actual input. It does this, because it reuses editors and swaps the underlying model/input. We need a way to respond to thatsetInput
call, and so I extended theonRender
call to not just respond with a disposable, but also with an optionalsetInput
.