scalameta / metals-vscode

Visual Studio Code extension for Metals
https://marketplace.visualstudio.com/items?itemName=scalameta.metals#overview
Apache License 2.0
297 stars 74 forks source link

[VSCode] Metals is generating files on click the extension view, even if I'm not in a Scala project #1439

Open RaniAgus opened 7 months ago

RaniAgus commented 7 months ago

Describe the bug

I opened VSCode in an Angular application and accidentally clicked Metals tab. There are two files that got generated and they shouldn't because I'm not in a Scala project and I din't click the "Start Metals" button.

image

image

Expected behavior

No files should be generated

Operating system

Windows

Editor/Extension

VS Code

Version of Metals

v1.1.0

Extra context or search terms

2023.11.29 09:13:21 INFO  Started: Metals version 1.1.0 in folders 'xxxxxx' for client Visual Studio Code 1.84.2.
2023.11.29 09:13:22 WARN  Build server is not auto-connectable.
2023.11.29 09:13:22 WARN  no build tool detected in workspace 'xxxxxx'. The most common cause for this problem is that the editor was opened in the wrong working directory, for example if you use sbt then the workspace directory should contain build.sbt. 
tgodzik commented 7 months ago

Thanks for reporting! This is the default behaviour of VS Code currently. When the tab is opened, VS Code will start the extension responsible for that tab :/ We don't define it ourselves.

There is even a note about the change https://code.visualstudio.com/api/references/activation-events#onView

tgodzik commented 7 months ago

We might be able not work around it, but not sure currently how to do it.

kasiaMarek commented 7 months ago

This will get automatically resolved if we add single files support https://github.com/scalameta/metals/pull/5531.

RaniAgus commented 7 months ago

Have you considered using a temporary folder for logging instead of a relative path?

https://github.com/scalameta/metals/blob/06b8ea1945a855dbcc539b840c8cdced600cff31/metals/src/main/scala/scala/meta/internal/metals/Directories.scala#L15-L16

tanishiking commented 7 months ago

There could be 2 solutions regarding the issue if https://github.com/scalameta/metals-vscode/issues/1439#issuecomment-1831925338 didn't work, my 2 cents :) I think writing log files into tmp dir would be ok, but I believe (2) is nicer + Metals still has some usage for .metals (should we use /tmp for those purposes too? e.g. swtich-build-server setting, I don't think so, but we may workaround by store the setting on client-side).

anatoliykmetyuk commented 7 months ago

Could a solution be to check if the current folder contains files like *.sbt, *.scala or *.sc before creating the .metals directory?

tgodzik commented 7 months ago

Probably something like that, basically duplicating the activation triggers, which we defined :/

YSMull commented 4 months ago

The problem was so severe that if the file he generated was deleted, it would be immediately regenerated, which was devastating