-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metals removes package syntax in Emacs 27 #4888
Comments
Thanks for reporting! Metals shouldn't remove the package statement, only add it if needed, which is unexpected. Would you possible be able to create |
Sorry. I couldn't find |
|
How do I create it? Is |
Just manually create an empty files, for example |
This is a full content of the [Trace - 02:14:03 AM] Received request 'initialize - (1)'
Params: {
"workDoneToken": "1",
"processId": null,
"rootPath": "/root/hoge",
"rootUri": "file:///root/hoge",
"initializationOptions": {
"decorationProvider": true,
"inlineDecorationProvider": true,
"didFocusProvider": true,
"executeClientCommandProvider": true,
"doctorProvider": "html",
"statusBarProvider": "on",
"debuggingProvider": true,
"treeViewProvider": true,
"quickPickProvider": true,
"inputBoxProvider": true,
"commandInHtmlFormat": "vscode"
},
"capabilities": {
"workspace": {
"applyEdit": true,
"workspaceEdit": {
"documentChanges": true,
"resourceOperations": [
"create",
"rename",
"delete"
]
},
"didChangeWatchedFiles": {
"dynamicRegistration": true
},
"symbol": {
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
]
}
},
"executeCommand": {
"dynamicRegistration": false
},
"workspaceFolders": true,
"configuration": true,
"codeLens": {
"refreshSupport": true
},
"fileOperations": {
"didCreate": false,
"willCreate": false,
"didRename": true,
"willRename": true,
"didDelete": false,
"willDelete": false
}
},
"textDocument": {
"synchronization": {
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
},
"completion": {
"completionItem": {
"snippetSupport": true,
"documentationFormat": [
"markdown",
"plaintext"
],
"deprecatedSupport": true,
"insertReplaceSupport": true,
"resolveSupport": {
"properties": [
"documentation",
"detail",
"additionalTextEdits",
"command"
]
},
"insertTextModeSupport": {
"valueSet": [
1,
2
]
}
},
"contextSupport": true,
"dynamicRegistration": true
},
"hover": {
"contentFormat": [
"markdown",
"plaintext"
],
"dynamicRegistration": true
},
"signatureHelp": {
"signatureInformation": {
"parameterInformation": {
"labelOffsetSupport": true
}
},
"dynamicRegistration": true
},
"documentSymbol": {
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
]
},
"hierarchicalDocumentSymbolSupport": true
},
"formatting": {
"dynamicRegistration": true
},
"rangeFormatting": {
"dynamicRegistration": true
},
"onTypeFormatting": {
"dynamicRegistration": true
},
"declaration": {
"linkSupport": true,
"dynamicRegistration": true
},
"definition": {
"linkSupport": true,
"dynamicRegistration": true
},
"typeDefinition": {
"linkSupport": true,
"dynamicRegistration": true
},
"implementation": {
"linkSupport": true,
"dynamicRegistration": true
},
"codeAction": {
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"",
"quickfix",
"refactor",
"refactor.extract",
"refactor.inline",
"refactor.rewrite",
"source",
"source.organizeImports"
]
}
},
"isPreferredSupport": true,
"dataSupport": true,
"resolveSupport": {
"properties": [
"edit",
"command"
]
},
"dynamicRegistration": true
},
"documentLink": {
"tooltipSupport": true,
"dynamicRegistration": true
},
"rename": {
"prepareSupport": true,
"dynamicRegistration": true
},
"publishDiagnostics": {
"relatedInformation": true,
"tagSupport": {
"valueSet": [
1,
2
]
},
"versionSupport": true
},
"foldingRange": {
"dynamicRegistration": true
},
"typeHierarchy": {
"dynamicRegistration": true
},
"callHierarchy": {
"dynamicRegistration": false
},
"selectionRange": {
"dynamicRegistration": true
},
"linkedEditingRange": {
"dynamicRegistration": true
}
},
"window": {
"workDoneProgress": true,
"showDocument": {
"support": true
}
}
},
"clientInfo": {
"name": "emacs",
"version": "GNU Emacs 27.1 (build 1, aarch64-unknown-linux-gnu)\n of 2022-01-25, modified by Debian"
}
}
[Trace - 02:14:04 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:04 INFO logging to file /root/hoge/.metals/metals.log"
}
[Trace - 02:14:04 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:04 INFO Started: Metals version 0.11.10 in workspace \u0027/root/hoge\u0027 for client emacs GNU Emacs 27.1 (build 1, aarch64-unknown-linux-gnu)\n of 2022-01-25, modified by Debian."
}
[Trace - 02:14:07 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:07 INFO time: initialize in 3.11s"
}
[Trace - 02:14:07 AM] Sending response 'initialize - (1)'. Processing request took 3211ms
Result: {
"capabilities": {
"textDocumentSync": {
"openClose": true,
"change": 1,
"save": {
"includeText": true
}
},
"hoverProvider": true,
"completionProvider": {
"resolveProvider": true,
"triggerCharacters": [
".",
"*"
]
},
"signatureHelpProvider": {
"triggerCharacters": [
"(",
"[",
","
]
},
"definitionProvider": true,
"typeDefinitionProvider": true,
"implementationProvider": true,
"referencesProvider": true,
"documentHighlightProvider": true,
"documentSymbolProvider": true,
"workspaceSymbolProvider": true,
"codeActionProvider": {
"codeActionKinds": [
"quickfix",
"refactor",
"source.organizeImports"
]
},
"codeLensProvider": {
"resolveProvider": false
},
"documentFormattingProvider": true,
"documentRangeFormattingProvider": false,
"documentOnTypeFormattingProvider": {
"firstTriggerCharacter": "\n",
"moreTriggerCharacter": [
"\""
]
},
"renameProvider": {
"prepareProvider": true
},
"foldingRangeProvider": true,
"executeCommandProvider": {
"commands": [
"build-restart",
"presentation-compiler-restart",
"analyze-stacktrace",
"list-build-targets",
"extract-method",
"debug-adapter-start",
"new-scala-file",
"build-connect",
"doctor-run",
"insert-inferred-type",
"compile-clean",
"generate-bsp-config",
"build-disconnect",
"copy-worksheet-output",
"reset-choice",
"goto",
"new-scala-project",
"ammonite-stop",
"scalafix-run",
"build-import",
"sources-scan",
"bsp-switch",
"new-java-file",
"reset-notifications",
"extract-member-definition",
"ammonite-start",
"compile-cancel",
"goto-super-method",
"goto-position",
"compile-cascade",
"convert-to-named-arguments",
"discover-tests",
"scala-cli-stop",
"super-method-hierarchy",
"scala-cli-start",
"file-decode"
]
},
"workspace": {
"fileOperations": {
"willRename": {
"filters": [
{
"pattern": {
"glob": "**/*.scala",
"matches": "file"
}
},
{
"pattern": {
"glob": "**/",
"matches": "folder"
}
}
]
}
}
},
"callHierarchyProvider": true,
"selectionRangeProvider": true,
"experimental": {
"rangeHoverProvider": true
}
},
"serverInfo": {
"name": "Metals",
"version": "0.11.10"
}
}
[Trace - 02:14:07 AM] Received notification 'initialized'
Params: {}
[Trace - 02:14:07 AM] Sending request 'client/registerCapability - (1)'
Params: {
"registrations": [
{
"id": "1",
"method": "workspace/didChangeWatchedFiles",
"registerOptions": {
"watchers": [
{
"globPattern": "file:///root/hoge/*.sbt"
},
{
"globPattern": "file:///root/hoge/pom.xml"
},
{
"globPattern": "file:///root/hoge/*.sc"
},
{
"globPattern": "file:///root/hoge/*?.gradle"
},
{
"globPattern": "file:///root/hoge/*.gradle.kts"
},
{
"globPattern": "file:///root/hoge/project/*.{scala,sbt}"
},
{
"globPattern": "file:///root/hoge/project/project/*.{scala,sbt}"
},
{
"globPattern": "file:///root/hoge/project/build.properties"
}
]
}
}
]
}
[Trace - 02:14:07 AM] Sending request 'workspace/configuration - (2)'
Params: {
"items": [
{
"section": "metals"
}
]
}
[Trace - 02:14:07 AM] Received notification 'workspace/didChangeConfiguration'
Params: {
"settings": {
"metals": {
"java-home": "",
"sbt-script": "",
"gradle-script": "",
"maven-script": "",
"mill-script": "",
"scalafmt-config-path": "",
"scalafix-config-path": "",
"bloop-sbt-already-installed": false,
"super-method-lenses-enabled": false,
"show-inferred-type": false,
"show-implicit-arguments": false,
"show-implicit-conversions-and-classes": false,
"enable-indent-on-paste": false,
"remote-language-server": "",
"fallback-scala-version": "3.2.0",
"test-user-interface": "Code Lenses",
"java-format": {
"eclipse-config-path": "",
"eclipse-profile": ""
},
"scala-cli-launcher": ""
}
}
}
[Trace - 02:14:07 AM] Received notification 'textDocument/didOpen'
Params: {
"textDocument": {
"uri": "file:///root/hoge/Main.scala",
"languageId": "scala",
"version": 0,
"text": "\n\nobject Main {\n @main def hello \u003d println(\"hello world\")\n}\n"
}
}
[Trace - 02:14:07 AM] Received request 'textDocument/codeLens - (2)'
Params: {
"textDocument": {
"uri": "file:///root/hoge/Main.scala"
}
}
[Trace - 02:14:07 AM] Received notification '$/cancelRequest'
Params: {
"id": 2
}
[Trace - 02:14:07 AM] Sending response 'textDocument/codeLens - (2)'. Processing request took 12ms
Result: null
[Trace - 02:14:07 AM] Received request 'textDocument/codeLens - (3)'
Params: {
"textDocument": {
"uri": "file:///root/hoge/Main.scala"
}
}
[Trace - 02:14:07 AM] Received notification 'metals/didFocusTextDocument'
Params: "file:///root/hoge/Main.scala"
[Trace - 02:14:07 AM] Received request 'textDocument/documentSymbol - (4)'
Params: {
"textDocument": {
"uri": "file:///root/hoge/Main.scala"
}
}
[Trace - 02:14:07 AM] Received request 'textDocument/codeAction - (5)'
Params: {
"textDocument": {
"uri": "file:///root/hoge/Main.scala"
},
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"context": {
"diagnostics": []
}
}
[Trace - 02:14:08 AM] Sending response 'textDocument/documentSymbol - (4)'. Processing request took 1169ms
Result: [
{
"name": "Main",
"kind": 2,
"range": {
"start": {
"line": 2,
"character": 0
},
"end": {
"line": 4,
"character": 1
}
},
"selectionRange": {
"start": {
"line": 2,
"character": 7
},
"end": {
"line": 2,
"character": 11
}
},
"detail": "",
"children": [
{
"name": "hello",
"kind": 6,
"range": {
"start": {
"line": 3,
"character": 2
},
"end": {
"line": 3,
"character": 42
}
},
"selectionRange": {
"start": {
"line": 3,
"character": 12
},
"end": {
"line": 3,
"character": 17
}
},
"detail": "",
"children": []
}
]
}
]
[Trace - 02:14:08 AM] Received notification '$/cancelRequest'
Params: {
"id": 4
}
[Trace - 02:14:08 AM] Received request 'textDocument/documentSymbol - (6)'
Params: {
"textDocument": {
"uri": "file:///root/hoge/Main.scala"
}
}
[Trace - 02:14:08 AM] Received notification '$/cancelRequest'
Params: {
"id": 5
}
[Trace - 02:14:08 AM] Sending response 'textDocument/codeAction - (5)'. Processing request took 1157ms
Result: null
[Trace - 02:14:08 AM] Received request 'textDocument/codeAction - (7)'
Params: {
"textDocument": {
"uri": "file:///root/hoge/Main.scala"
},
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"context": {
"diagnostics": []
}
}
[Trace - 02:14:08 AM] Sending response 'textDocument/documentSymbol - (6)'. Processing request took 20ms
Result: [
{
"name": "Main",
"kind": 2,
"range": {
"start": {
"line": 2,
"character": 0
},
"end": {
"line": 4,
"character": 1
}
},
"selectionRange": {
"start": {
"line": 2,
"character": 7
},
"end": {
"line": 2,
"character": 11
}
},
"detail": "",
"children": [
{
"name": "hello",
"kind": 6,
"range": {
"start": {
"line": 3,
"character": 2
},
"end": {
"line": 3,
"character": 42
}
},
"selectionRange": {
"start": {
"line": 3,
"character": 12
},
"end": {
"line": 3,
"character": 17
}
},
"detail": "",
"children": []
}
]
}
]
[Trace - 02:14:08 AM] Received notification '$/cancelRequest'
Params: {
"id": 3
}
[Trace - 02:14:08 AM] Sending response 'textDocument/codeLens - (3)'. Processing request took 1400ms
Result: null
[Trace - 02:14:08 AM] Received request 'textDocument/codeLens - (8)'
Params: {
"textDocument": {
"uri": "file:///root/hoge/Main.scala"
}
}
[Trace - 02:14:08 AM] Received notification '$/cancelRequest'
Params: {
"id": 8
}
[Trace - 02:14:08 AM] Sending response 'textDocument/codeLens - (8)'. Processing request took 8ms
Result: null
[Trace - 02:14:08 AM] Received request 'textDocument/codeLens - (9)'
Params: {
"textDocument": {
"uri": "file:///root/hoge/Main.scala"
}
}
[Trace - 02:14:08 AM] Sending response 'textDocument/codeAction - (7)'. Processing request took 69ms
Result: []
[Trace - 02:14:08 AM] Received response 'client/registerCapability - (1)' in 1525ms
Result: null
Error: null
[Trace - 02:14:08 AM] Received response 'workspace/configuration - (2)' in 1516ms
Result: [
{
"java-home": "",
"sbt-script": "",
"gradle-script": "",
"maven-script": "",
"mill-script": "",
"scalafmt-config-path": "",
"scalafix-config-path": "",
"bloop-sbt-already-installed": false,
"super-method-lenses-enabled": false,
"show-inferred-type": false,
"show-implicit-arguments": false,
"show-implicit-conversions-and-classes": false,
"enable-indent-on-paste": false,
"remote-language-server": "",
"fallback-scala-version": "3.2.0",
"test-user-interface": "Code Lenses",
"java-format": {
"eclipse-config-path": "",
"eclipse-profile": ""
},
"scala-cli-launcher": ""
}
]
Error: null
[Trace - 02:14:08 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:08 WARN Build server is not auto-connectable."
}
[Trace - 02:14:08 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:08 WARN no build tool detected in workspace \u0027/root/hoge\u0027. 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. "
}
[Trace - 02:14:08 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:08 WARN no build target for: /root/hoge/Main.scala"
}
[Trace - 02:14:08 AM] Sending notification 'metals/status'
Params: {
"text": "No build tool",
"show": true,
"command": "metals-logs-toggle"
}
[Trace - 02:14:14 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:14 INFO no build target found for /root/hoge/Main.scala. Using presentation compiler with project\u0027s scala-library version: 3.2.0"
}
[Trace - 02:14:15 AM] Sending notification 'metals/status'
Params: {
"text": "",
"hide": true
}
[Trace - 02:14:18 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:18 INFO time: code lens generation in 11s"
}
[Trace - 02:14:18 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:18 INFO time: code lens generation in 9.59s"
}
[Trace - 02:14:18 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:18 INFO time: code lens generation in 10s"
}
[Trace - 02:14:18 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:18 INFO time: code lens generation in 9.59s"
}
[Trace - 02:14:18 AM] Sending response 'textDocument/codeLens - (9)'. Processing request took 9590ms
Result: []
[Trace - 02:14:24 AM] Received request 'textDocument/codeAction - (10)'
Params: {
"textDocument": {
"uri": "file:///root/hoge/Main.scala"
},
"range": {
"start": {
"line": 1,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"context": {
"diagnostics": []
}
}
[Trace - 02:14:24 AM] Sending response 'textDocument/codeAction - (10)'. Processing request took 43ms
Result: []
[Trace - 02:14:25 AM] Received request 'textDocument/codeAction - (11)'
Params: {
"textDocument": {
"uri": "file:///root/hoge/Main.scala"
},
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"context": {
"diagnostics": []
}
}
[Trace - 02:14:25 AM] Sending response 'textDocument/codeAction - (11)'. Processing request took 21ms
Result: []
[Trace - 02:14:27 AM] Received request 'shutdown - (12)'
Params: null
[Trace - 02:14:27 AM] Sending notification 'window/logMessage'
Params: {
"type": 4,
"message": "2023.01.24 02:14:27 INFO shutting down Metals"
}
[Trace - 02:14:27 AM] Sending response 'shutdown - (12)'. Processing request took 94ms
Result: {} |
This happens for me as well 😢 |
@t-matsudate did this happen again after you created the file? @bjekt what is the exact issue in your case? The issue here happens when no project is available. Your problem seems connected to the new functionalty that should rename all references when we change package, so that might be a bit different. |
@tgodzik I make a change to a file and it removes the package line - it also updates all references in imports in other files. |
Interesting, it should only be invoked on |
Yes. Anytime but irregularly this matter happens. |
Ah, could this be related to autostore (i.e. emacs automated backups)? |
|
@bjekt that might be the issue, we did some workarounds for it, but it's problematic to work with. It probably invokes the
|
@tgodzik I managed to exclude the git diffs by modifying the |
There is no filter currently, we should apply it automatically for users. Is there anything specific about the files that we could maybe use? Are they readonly? |
It might be that #4891 will fix it. For emacs it would probably be good to ignore the file names starting with I tried building my own metals the other day to try to add some filter but hit some roadblocks so had to go back. |
What types of issues did you hit on? If you are still willing I'm happy to try and debug what you were hitting on in order to build and publish it locally. |
@bjekt are the files also readonly? Prefix plus |
@tgodzik The thing is that they seems to be created in the same directory, file watcher is picking them up and then they are moved by emacs to the final directory immediately. |
#4904 This seems to fix it. |
Actually it did just kick in a bit later. |
src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala:L2142
I still haven't been able to figure out why this move is being sent. |
Are you able to figure out the |
Let's see if #4967 helps |
@bjekt Are you able to check out |
Nice ! Looks good so far - I'll continue testing during the day. Thanks a lot for this fix @tgodzik ! |
I'd like to check about changes in this snapshot. But I don't know how do I install this into Emacs. |
Hi @t-matsudate
You need to find the current location for your metals-emacs and replace the -o option accordingly. |
@tgodzik I had no issues yesterday. I think you nailed it! |
Great to hear! Thanks for helping out with figuring the issue! |
Describe the bug
In Emacs, Metals removes Scala3's package syntax when saves it's source code.
Emacs+Metals_SD.360p_MEDIUM_FR30.mp4
Environments:
Reproduce:
Note: This matter occurs irregularly.
Expected behavior
This syntax isn't removed.
Operating system
Linux
Editor/Extension
Emacs (lsp-metals)
Version of Metals
v0.11.10
Extra context or search terms
No response
The text was updated successfully, but these errors were encountered: