scalameta / metals

Scala language server with rich IDE features 🚀

Home Page:https://scalameta.org/metals/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Package definitions stripped out when moving files to locations Metal's doesn't understand, imports mangled.

davesmith00000 opened this issue · comments

Describe the bug

I'm not sure the exact steps to reproduce, but I've seen this on numerous occasions. I'll explain what I was doing.

I have a module that was set up as a crossProject in sbt (using sbt as the language server), I change it's definition to being from:

crossProject(JSPlatform, JVMPlatform).crossType(CrossType.Full)

to:

crossProject(JSPlatform).crossType(CrossType.Pure).withoutSuffixFor(JSPlatform)

From a code organisation point of view, this means you remove the js/src, jvm/src, and shared/src folders, and replace them with one top level src folder.

By now, Metals is understandably in some state of confusion.

I now need to consolidate all those old folders and their contents into the src folder, and I do that by dragging them in VSCode (the workaround is to do this in your OS file manager), and Metals tries to help by adjusting package definitions and imports.

It is normally pretty good at this, but in this scenario I guess it thinks the src is outside the scope of the project, and so it just removes the package definitions, and removes the qualified paths from imports. For example:

package x

trait Y

becomes (note the empty line at the top):


trait Y

...and references to Y in imports change from import x.Y to import Y. Which is incorrect. In fact the original definitions where exactly right.

Expected behavior

When moving a file to a location that metal's doesn't understand / thinks is outside the current project structure:

a) Leave package definitions intact.
b) Leave imports intact.

Operating system

Linux

Editor/Extension

VS Code

Version of Metals

1.2.2+102-8e3b9cea-SNAPSHOT

Extra context or search terms

No response