Subscribe to this thread
Home - General / All posts - VSCode extension for Manifold 9's SQL
rk
645 post(s)
#04-Oct-22 07:28

I started a VSCode extension for Manifold 9's SQL, that we have thought about.

Please try it out and suggest ideas.

I have not yet published it, but you can install it manually.

https://github.com/rkolka/sql-manifold-9

Attachments:
sample_v0.1.8.png

oeaulong

535 post(s)
#04-Oct-22 13:52

nice. Thanks for this.

tjhb
10,105 post(s)
#04-Oct-22 18:17

Fantastic Riivo.

Are there any areas where you need help?

Will tey this out today.

rk
645 post(s)
#04-Oct-22 22:00

Yes, there is so much to do with snippets. Lots of fun too. I had one vision, but I'm learning how to create even better snippets.

For multiline snippets there is a tool that helps.

https://vscodesnippetgenerator.azurewebsites.net/

And some day built in functions should autocomplete and give doc hints, etc. But this is going to be TypeScript programming, away from current declarative json and stuff.

tjhb
10,105 post(s)
#04-Oct-22 22:07

Not interested in code snippets. I might not understand. What are they exactly for?

To make beginners write code like everyone else, without invention?

To prevent programmers from thinking for themselves?

To perpetuate bugs?

Any of these would be evil, don’t you think?

As I said, I don’t understand.

rk
645 post(s)
#04-Oct-22 22:35

I's say snippets are a kind of autocomplete. They can help avoid syntax errors. They are not evil, just a particular way to solve a problem. A way that VSCode provides without writing TypeScript.

tjhb
10,105 post(s)
#04-Oct-22 22:43

OK. Evil.

Let me just ask you:

If you were running a programming team—like the team that drives Manifold—would you allow, or disallow, code snippets?

(Yes, a dream, but it is a valid dream. Would you? No. Because evil.)

rk
645 post(s)
#05-Oct-22 00:10

OK, let's first try to agree on some properties that are desirable. And then we can argue if snippets are an appropriate solution. I won't comment on dream team Manifold.

  • consistent code style. Desirable?
  • customizable way to do what Transform templates do. Desirable?
  • allowing only valid choices in syntax. Desirable?
  • ...

tjhb
10,105 post(s)
#05-Oct-22 00:28

I am not a real coder Riivo, I am always a beginner. So I don’t know.

But I will andwer all the same!

* consistent coding style—desirable? Yes, but only if it takes effort and work. If it were automatic, then no, completely and utterly worthless.

* customizable way to do what Transform templates do—well, we have that already (the Edit Query button), and again, removing the necessity to think would not be an improvement.

* allowing only valid choices in syntax—desirable? No. It is an important part of learning to make mistakes (even stupid, trivial ones). Showing mistakes is good, correcting them automatically is very very very bad.

rk
645 post(s)
#04-Oct-22 23:22

I think, for me snippets can raise the level of abstraction.

Maybe it is evil.

Any tool can be used evilly.

Attachments:
Add-GEOM-and-DRAWING.mp4

hugh
200 post(s)
#05-Oct-22 03:03

?? code snippets are exactly what M9 provides in the bottom left Query Bulder pane. Are they evil too? I could not function without them.

tjhb
10,105 post(s)
#05-Oct-22 03:16

There are no code snippets there. They are syntax definitions.

Can you give a screenshot of what you mean?

oeaulong

535 post(s)
#04-Oct-22 22:27

Snippets in my past have helped speed code painting, while keeping syntax clean. I don't quite see the SQL need yet, but will check out the link. I found them most useful for conditional and looping structures which I don't quite see often in mfdSQL. It is probably due to my simplistic query structure. There does seem to be inline parenthetical code that I could see snippet expansion.

tjhb
10,105 post(s)
#04-Oct-22 22:55

What is “code painting”? Is speed good?

oeaulong

535 post(s)
#04-Oct-22 23:38

just a term that that popped into my head.

"Is speed good?" When language and command syntax gets tedious, speeding up the process by changing the tedium into precision, then yes it's good. With your prior comments, you are calling it a BadThing. I couldn't disagree more. If I was a team lead for a programming group, I wouldn't make mandatory, it is up to each developer to use or not use a tool that works for them. If I saw it impact the code base in a negative way, then I would help to address the issue. I don't believe for a minute that it is due to the use of auto-completion/snippets in isolation, the problem must exist in the user of the tool. Good methodology wins.

My comments include most all of the languages I've coded in. Having that capability in Manifold queries isn't something I have used, but have used the built in UI shortcuts to help be precise about function use. How I might use code snippets in Mfd is still in question until I get a chance to play with it. Perhaps it is not so useful for SQL, i don't find it useful for Assembly. I am liking the effort RK is putting into bringing some nice VScode features of presentation to help with future query writing.

tjhb
10,105 post(s)
#05-Oct-22 00:31

Speed in coding is bad.

Imagination and accuracy are good, take time, and can’t be guessed by AI.

i don't find it useful for Assembly.

Exactly.

I am liking the effort RK is putting into bringing some nice VScode features of presentation to help with future query writing.

Me too! But not so far as automating code. That would be bad bad bad.

rk
645 post(s)
#04-Oct-22 23:36

Tim.

What part of it you would like to extend?

tjhb
10,105 post(s)
#05-Oct-22 00:46

The correct way for me to help is (not to comment spuriously but) to test.

So I will.

You are thorough. I don’t expect to find the sort of gaps that I would have left.

adamw


10,447 post(s)
#05-Oct-22 13:28

Just saw this. Wow! Very cool. :-)

Dimitri


7,479 post(s)
#20-Aug-23 07:52

Aside from being brain-dead, I have no excuse for not earlier using this really super extension to vscode. :-) It is sooo much better than plain text editing. Heck, it saves tons of time just for keeping parens sorted out. Thank you, Riivo!

For any other beginners out there, here is a quick guide to installing Visual Studio Code (VSCode or just "code") and also the extension:

1. Install vscode. It's free. There are many great tutorials online for installing and working with vscode. If you're totally new to vscode, Daniel Gakwaya has very detailed, step by step instructions for installing it in the first part of his big courses on learning C++, like his free 31 hour course at freecodecamp.org. The first comment in the YouTube page for that video provides handy bookmarks for jumping around in the very long video. If you want to learn C++ Daniel's paid course on Udemy is even more comprehensive, better organized, has many student assignments, and is worth every dollar.

2. Get the extension: Visit Riivo's github page at the link in his post. Click the green "Code" button and choose "download ZIP" to download everything. Unzip the file into a convenient folder.

3. Launch vscode (remember to do that from within a Developer Command Prompt window, as Daniel and others recommend).

4. In vscode, choose View - Extensions to open the Extensions pane.

5. In the toolbar at the top of the Extensions pane, click on the [...] button and choose Install from VSIX.

6. In the install from VSIX dialog, navigate into the dist subfolder of the unzipped distribution from Riivo's site, and choose sql9.vsix. Code will install the extension.

To use the extension, in code's main toolbar choose File - New Text File and then in the default text that pops open choose Select a Language. Scroll down to Manifold 9 SQL and choose that. You now have a new text file open in vscode that is enabled with Riivo's extension to understand Manifold 9 SQL syntax.

If you haven't worked with VSCode before, it's a wonderful cross-platform editor for programming of all kinds.

rk
645 post(s)
#20-Aug-23 21:22

Thanks.

I updated it a bit and made a release on github. Only the .vsix file is necessary.

artlembo


3,425 post(s)
#20-Aug-23 22:37

this is very good. I've thrown a lot of my queries in it, and it is great to see the syntax and also seeing where parentheses need to close. Great job!! I'll be using this going forward with my SQL.

As Dimitri says,

It is sooo much better than plain text editing.

But, it does beg the question...

after all these years of people asking for syntax highlighting, why does it take Rivo to do this? Why hasn't Manifold built a decent intellisense into the product?

Having to write code in Manifold using a text editor has been a pain, and the closest I could get was copy/paste into/from Notepad++.

Not having something like what Rivo built is incredibly difficult to use and adopt, and embarrassing when my professional developer friends see all the code having to be written in a plain text editor in the program.

I would hope that Manifold would start to natively roll this into the product.

danb

2,067 post(s)
#20-Aug-23 22:52

Firm but fair


Landsystems Ltd ... Know your land | www.landsystems.co.nz

Dimitri


7,479 post(s)
#21-Aug-23 08:05

Let's see...

all these years of people asking for syntax highlighting

Fair questions. When exploring answers, it's important to check the assumptions that go into them. For example, if you search the forum for "syntax highlighting" there are eight people who have posted a comment since 9 came out of beta that syntax highlighting for SQL would be good. Half of those posts were a one-time, off the cuff mention.

Experience shows that when people post "yes, I'd like that too..." in the forum virtually none of them take a couple of minutes to send in a suggestion. So it would not be surprising if only two people since 9 came out of beta sent in a suggestion for SQL syntax highlighting.

It's also important not to underestimate the convenience of what is already there. For example, like this:

all the code having to be written in a plain text editor in the program.

But Query Builder is not a plain text editor. On the contrary it is a rich tool for building queries that provides important workflow efficiency that VSCode does not provide.

For example, Query Builder provides drag and drop utilization of tables and fields in the project, as well as very convenient point-and-click access to well-organized statements, operators, tuple operators, aggregate functions, functions, types, three different varieties of vector types, collate options, constants, pragmas, preprocessor directives and thread configuration.

The tables pane in Query Builder shows tables with their fields and schemas. Don't get that in vscode. The tables pane also has a filter box that allows fast reduction of what might be dozens of tables and thousands of fields to just those of interest. The functions pane likewise has a filter box for very convenient reducing of long lists to items of interest. There are also higher level commands like inserting entire CREATE TABLE definitions of a table and inserting a field list. Sure, you can add a snippet to vscode to create a generic table, but that snippet will not examine a specific, complex table and with a click write the SQL to CREATE such a table.

As for functions, yes, of course you can add snippets to vscode to add function shortcuts, like this...

"GeomArea":{

"scope": "sql9",

"prefix": "GeomArea",

"body": "GeomArea(${1:Geom},0)"

,

"description": "compute Euclidean area of a geom"

},

...but picking the GeomArea function out from a very long list of offered snippets in vscode is not as convenient as picking in the hierarchical/filtered list in the Query Builder. Anybody who has lots of user snippets in vscode knows what I mean.

In vscode, for longer function names you must know the name of the function to reduce to a manageable size the snippet list that is presented as you start keyboarding the name of the function, and you often need to keyboard a lot to get to where you can then pick off the snippet list the one you want. With Query Builder you can just browse the hierarchy very rapidly to find functions that you want where you don't remember the exact name.

Also, once you've picked a snippet in vscode you may have the function framework, but populating arguments from tables and fields is not a simple matter of pointing and clicking in the table schema like in the Query Builder. That's a real time saver.

I'm not in any way arguing against vscode. I like vscode and I use it almost every day, but I use it for C++ or C#, not for SQL. As much as I like what the extension does (it really is a super thing), I'll continue to use the Query Builder, probably going back and forth between the Query Builder and vscode.

My primary edit environment will likely continue to be Query Builder because I haven't used vscode for much more than convenient auto-reckoning of nested parentheses. As a speed thing, for me it is much more important to get the point and click addition of fields and functions than it is to see colors to tell me what is SELECT, what is a table, what is a field, and what is a function or a function argument. Sensibly formatting SQL for legibility is something that got wired into my nervous system many, many years ago, so I do that automatically without even thinking about it.

So yes, vscode with the extension is, hands down, better than Notepad, but it's not as convenient/efficient for the queries I write as the Query Builder. That's OK, as it takes but a moment to do a Ctrl-A, Ctrl-C to copy what's in the Query Builder and then a Ctrl-A, Ctrl-V to paste into vscode, and, voila! pretty colors and automatic reckoning of all the parentheses.

I think what advanced SQL authors really would like is something that combines what Manifold provides in Query Builder together with what Microsoft provides in VSCode.

OK, so why didn't Manifold invest into providing syntax highlighting in Query Builder?

The answer to that is simple: low demand for that compared to demand for other things, as my comment at the top of this post points out. That shouldn't come as a surprise because whenever there already is an existing solution to some desire the demand for duplicating that wheel within Manifold is, understandably, less than the demand for adding something to Manifold which cannot be obtained off the shelf within an existing solution.

The early experience of Manifold was that people who write extensive SQL tend to already have some SQL editor they know and love. So it's understandable that demand from such users for a competing SQL editor within Manifold would be low.

Most people who write SQL in Manifold use SQL in relatively simple ways. Most SQL is simple SQL, because you can get a lot done with simple SQL. Such people tend to value the point and click conveniences of Query Builder, and they don't write such extensive SQL where a full featured programming editor created for large projects, like Visual Studio Code, might help. So it's understandable that people writing simple SQL don't lobby for a vscode clone within Manifold.

So that leaves the people in the middle, who (like me) write enough SQL code to want conveniences, but not so much that they already are devotees of some existing SQL coding environment.

For such people, Manifold had always intended to get around to adding syntax highlighting, even if demand for it was low in the broader community. If I recall correctly, about a year ago there was talk within Manifold to leverage Visual Studio Code, with an extension like Riivo provided. And then Riivo published his extension, which works great and provides syntax highlighting. It also provided a way to see how much interest there was for anything more.

Where we are today is that there is a really super extension contributed by Riivo that provides syntax highlighting. It's very well done and works great. For sure, Riivo's extension will be one of my regular tools for when I write more ambitious SQL.

As for the future, greater integration with vscode certainly is a possibility, but does it make sense to invest a lot of effort into that when it takes but half a second to go back and forth between code and Query Builder with a Ctrl-A, Ctrl-C/V? I think there are more useful things of wider interest to the community, for example, exposing more programming hooks to utilize and extend the capabilities already within Manifold.

The above is just my opinion. As a fanatic vscode user I like the extension and would enjoy seeing greater integration of vscode with 9. But I also respect that other people might prefer some other routes, like greater integration of notepad++ or some other editor that can do syntax highlighting, or might prefer that more important priorities get the resources.

Manifold User Community Use Agreement Copyright (C) 2007-2021 Manifold Software Limited. All rights reserved.