Skip to content
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

Please help me creating VS Code extension #36

Open
leodevbro opened this issue Dec 20, 2020 · 4 comments
Open

Please help me creating VS Code extension #36

leodevbro opened this issue Dec 20, 2020 · 4 comments

Comments

@leodevbro
Copy link

I want to create a VS Code extension with my specific idea, I have already made a DEMO in react.js, what do you think about it?

https://youtu.be/qrEKSe8VkYQ
(Block marking / Block highlighting)

I wrote the opening/closing block finding and nesting algorithm myself. The code link is in the video description.

Is it possible to create such extension in VS Code? I learned some basics of the extension API, created some testing blocks with createTextEditorDecorationType function, but it seems that the decoration manipulation is very limited, so limited that maybe it's not even possible to create as simple block marking feature as my DEMO.

@mattbierner
Copy link
Owner

mattbierner commented Dec 21, 2020

Neat idea!

I don't think you can create exactly what you are after with the current VS Code apis but there are two areas to explore:

  • First take a look at VS Code's existing folding support. This is also based on code blocks behind the scenes but uses this block information for folding instead of visually rendering them (although users can hover in the gutter to see folding ranges). At the very least, instead of writing your own algorithm to get the blocks, you could reuse the folding ranges so that your extension works across languages

  • For rendering, check out the decorations API: https://github.com/microsoft/vscode-extension-samples/tree/master/decorator-sample

    As you note this is limited but I believe you could use it to:

    • change the background color of some code
    • Add decorations in the gutter that shows the block ranges

    You may also be able to find some other creative ways to use decorations that let you show block ranges

Hope that provides some starting points to explore further

@leodevbro
Copy link
Author

leodevbro commented Dec 22, 2020

Thanks, yeah my algorithm works but using native VS Code inner system to find blocks would be much faster and less error prone.
I'll try your advices. I also found this open source project:

https://github.com/CoenraadS/Bracket-Pair-Colorizer-2

Which looks interesting because it "uses the same bracket parsing engine as VSCode", so maybe I can examine their code and learn how to get the locations of brackets {}[]() faster.

Folding ranges also sound very interesting. I'll try each way.

@leodevbro
Copy link
Author

Hello there again, I have super great news. the extension actually works, I did finish to the point of demonstration. It needs some polishing to be done, but the hardest part is complete. I'm still working, I'll inform you when I finish it or if I need any help.

VSCode API is hell sometimes : d
it was very hard to reach this point, but somehow did...

Blockman v0.9
https://youtu.be/ZmvLgIDJNg8

.

@leodevbro
Copy link
Author

I'm trying to get folding ranges for a file, I looked into the API, but could not find the right function. Can you write a sample code to get folding ranges for a file? Maybe the sample code will be just several lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants