dbaumgarten / yodk

Development Kit for Starbase's ingame programming language YOLOL
MIT License
57 stars 16 forks source link

Auto-Type: Lanugage-Server without vscode pastes the wrong file #98

Closed Firestar99 closed 2 years ago

Firestar99 commented 2 years ago

Describe the bug I use a different IDE to code my yolol and after optimization ran I go into VS to use Auto-Type to paste my stuff in-game. I open the build files via single-click (semi-opening them) and when doing that there is a chance Auto-Type just pastes in a different file, I think the previous one which was opened. Annoying when pasting multiple chips back to back.

I assume it is single-click opening related but not 100% yet, will do more testing if double-click is consistent.

To Reproduce Steps to reproduce the behavior:

  1. optimize your yolol-script of choise, outside VS
  2. go into VS, open file with single click (half-opening them)
  3. click on first line inside editor (not sure if this step is required)
  4. Paste inside Starbase SSC (Ctrl+Alt+O)
  5. Sometimes it pastes a different script

Expected behavior Paste the opened file, even if it was opened by single-click.

Platform:

Additional context Sorry if this one will be an annoying one to figure out :)

Firestar99 commented 2 years ago

Update: It has to do something with the file being changed externally, VS picks up the changed file and reloads it (I have autosave on), but somewhere in the chain something doesn't update the currently opened file. It is NOT opening the previously opened file ~but one specific file in particular is always selected for pasting (compass.yolol in my case, the alphabetically lowest file in the directory).~

Firestar99 commented 2 years ago

Update2: It is NOT opening the previously opened file or the first file of the directory... BUT completely random files. It just copied standard ISAN v2.5 which is in the same project but a completely different directory, and I haven't opened or copied in a while.

The best temp fix seems to be to spam click the file open or closing all files and reopen. Clicking into the file does not help.

dbaumgarten commented 2 years ago

I can't reproduces this one, like at all. Pasting scripts that are opened in preview mode (title of the tab is cursive) works just fine. And I really don't see any reason why this shouldn't work.

The extension contains this code:

vscode.window.onDidChangeActiveTextEditor(function(event) { 
    client.sendRequest( "workspace/executeCommand", {
        command: "activeDocument",
        arguments: [vscode.window.activeTextEditor.document.uri.toString()]
    })
})

So whenever the currently active text-editor changes, it tells the languageserver what the currently active file is (so it can then later use this script when pasting).

Do you have mutliple vscode-windows open? That could cause issues. When you look into the taskmanager while you have a yolol file open in vscode, is there more than one yodk-process running? What version of vscode are you using?

Firestar99 commented 2 years ago

When you look into the taskmanager while you have a yolol file open in vscode, is there more than one yodk-process running? 100% yes, has to.

One Instance: Intellij Idea with Language Server Addon configured to your language server for all .yolol files Second Instance: vscode with your Yolol Plugin. That could definently be causing the issue.

Good to know that pasting works via the language server and not the vscode plugin, like I assumed. Still does not explain it pasting files I never had opened either in idea nor vscode.

As a workaround for know I'll disable the Language Server in idea, it doesn't integrate as well anyways (no code highlight). (Would still be cool if I can paste it straight out of any IDE, then I'd never have to open vscode)

dbaumgarten commented 2 years ago

So, if you don't have Intellij open everything works as expected?

Auto-typing from within the extension doesn't really work, as there seems to be no way to properly access the win32 API from withing NodeJS.

The hard part is telling the language-server which file the user is currently viewing. The Language Server Protocol has a DidOpen event, but that is only fired once fore each file. Thats why it needs that extra hack inside the extension I posted above. This hack isn't present in Intellij, so the language-server will only know for which document it received the last DidOpen-Event.

I suspect that Intellij tries to be smart and sends a DidOpen-Event for every file in the folder in the background (and that maybe in a random order). (Easy way to check this: Does Intellij report syntax-errors for files you didn't yet open?).

As a workaround you could start the language-server with ./yodk.exe langserv --hotkeys=false for intellij.

Syntax-highlighting is sadly not part of the LSP-Standard. There is nothing that can be done here.

Firestar99 commented 2 years ago

Will try that out later this evening if that fixes things, and thanks for the workaround! :)

Firestar99 commented 2 years ago

Yesterday I got the time to code a bit again and it worked perfectly.

As an improvement I think it could be great if --hotkeys=false would be mentioned in the docs of cli / language server section with the recommendation of turning it off for all IDEs other than vs-code, as it doesn't work correctly anyway (if I understood you correctly).

Maybe it would be even better to have yodk langserv have hotkeys disabled by default, but in the vscode extension has them enabled by default, then noone can accidentally get into my situation without knowingly enabling them in their IDE of choice.

dbaumgarten commented 2 years ago

I think disabling the hotkey-feature of the cli by default is the reasonable thing to do. Any ide that implements the extra-stuff needed to make it work properly (like vscode) can then enable it.

dbaumgarten commented 2 years ago

Published as part of v0.1.10