asg017 / dataflow

An experimental self-hosted Observable notebook editor, with support for FileAttachments, Secrets, custom standard libraries, and more!

Home Page:https://alexgarcia.xyz/dataflow/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Editor-agnostic auto-completion

asg017 opened this issue · comments

Say you have:

element = html`<div>
<table>
...`

update = {
  element;
}

When updating the update cell and accessing element, I want to be able to use autocompletion (ie, <Tab>) to see all th enumerable fields of the element cell's value. In this case, it's an HTML element, so I should see a dropdown list of querySelector, querySelectorAll, getAttribute, etc.

But I use VS Code, some people like vim, others emacs. Autocompletion in each editor would be different, but the same underlying list of enumerable fields should be the same for all potential editor clients.

  • In the client (index.html websocket client), send messages back of resolved cells and their enumerable fields
    • Which client? there could be multiple ones, would need the editor to "choose" which client to use (maybe a keyboard shortcut on the index.html to mark "I wanna see this clients enumerable fields"?)
    • Would this work for nested values? like d = {a: {b: {c: 7}}} could have a autosuggested path d.a.b.c, may need to request valid fields from the editor client -> dev server -> index.html client on every cell (seems like fun)
    • Doesn't have to be cells either, window/global values like document or window.location should be supported as well
    • Seems like dealing with VS code will be the hardest part of this

Hm, this sounds like a job for the custom Language Server (with an additional complication that it would have to fetch actual values from the browser window) -- but at least it should cover multiple editors simultaneously? the list of tools with LSP support is steadily growing

@wizzard0 that sounds right! I haven't played much with vscode language servers, but from what I've used before it sounds do-able. There would need to be some sort of "connection" between a selected client and your code editor of choice, where the client shared data on what cells are active/what keys can be accessed on those objects. I dont know of any other VS Code language server that does this sort of dynamic auto-complete option (I'd imagine most just do static analysis of your code to figure it out).

"Editor-agnostic" would be key here, idk if any other editor that has a "language server" like vscode, mostly because Ive never looked into it. Im sure that vim has some crazy extensions that can do this, or Atom

idk if any other editor that has a "language server" like vscode

The list of tools on LSP website looks quite decent! dunno about the quality of integrations in all of them though. But Rust, Go etc etc. already provide LSPs so it seems like it's on its way to becoming a de-facto standard.

https://microsoft.github.io/language-server-protocol/implementors/tools/