tgrospic / rholang-vscode

Rholang extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=tgrospic.rholang
MIT License
9 stars 6 forks source link

Document Formatting #4

Open arthurgreef opened 4 years ago

arthurgreef commented 4 years ago

Hi - is it possible to get a document formatting feature? Sometimes it is really hard to debug when you have a mismatched {} and the eval output error line number is the last line of the program, and the real problem is somewhere else.

tgrospic commented 4 years ago

Hi Arthur! Formatting is definitely very useful feature. Adding support to the extension or creating new formatting extension is not difficult part. Here is the summary. https://code.visualstudio.com/blogs/2016/11/15/formatters-best-practices#_summary

The part where all the formatting logic is in the implementation of DocumentFormattingEditProvider which should analyze selected Rholang code/file and do the work. I don't see support to work with parser output but only to work directly with string.

This basically means that, adding formatting support to the extension is hard as writing function (document: vscode.TextDocument): vscode.TextEdit[] (for range formatting position must be also included). Here is the simple formatting extension example. https://github.com/jrieken/vscode-formatter-sample/blob/master/src/extension.ts