Skip to content
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

Closed
t-matsudate opened this issue Jan 23, 2023 · 33 comments
Closed

Metals removes package syntax in Emacs 27 #4888

t-matsudate opened this issue Jan 23, 2023 · 33 comments

Comments

@t-matsudate
Copy link

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:

  • Ubuntu 22.10(AArch64) on Termux
  • Emacs 27
  • lsp-metals-20221014.853
  • Scala 3.2.1

Reproduce:

  1. Runs emacs and opens Scala's source file.
  2. Write some package syntax into first line.
  3. Adds several other syntax below package syntax.
  4. Executes M-xM-s.
  5. Somehow package syntax is removed.

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

@tgodzik
Copy link
Contributor

tgodzik commented Jan 23, 2023

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 .metals/lsp.trace.json file in the workspace you created and then send it to use? It should record all the interactions of the emacs and Metals.

@t-matsudate
Copy link
Author

Sorry. I couldn't find .metals/lsp.trace.json but could find .metals/metals.log instead. May I send this to you?

@tgodzik
Copy link
Contributor

tgodzik commented Jan 23, 2023

.metals/lsp.trace.json is not created automatically, you would need to create yourself and it will get populated then.

@t-matsudate
Copy link
Author

t-matsudate commented Jan 23, 2023

How do I create it? Is .metals/lsp.trace.json just putting into project? Or is there some command to create it?

@tgodzik
Copy link
Contributor

tgodzik commented Jan 23, 2023

Just manually create an empty files, for example touch .metals/lsp.trace.json

@t-matsudate
Copy link
Author

This is a full content of the .metals/lsp.trace.json:

[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: {}

@bjekt
Copy link

bjekt commented Jan 24, 2023

This happens for me as well 😢
It also updates all references in the project. (Scala 2.13)

@tgodzik
Copy link
Contributor

tgodzik commented Jan 24, 2023

@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.

@bjekt
Copy link

bjekt commented Jan 24, 2023

@tgodzik I make a change to a file and it removes the package line - it also updates all references in imports in other files.
It opens the files with references in new buffers with the modification. I.e. you modify a file that is referenced from many places you have 30 updates to undo. Pretty messy.

@tgodzik
Copy link
Contributor

tgodzik commented Jan 24, 2023

Interesting, it should only be invoked on willRenameFiles so whenever the file name is changed or it's moved, so this should not be an issue with changes in the file. Are you also using emacs? I could try and trace the issue in your LSP log the same as above to see what metals actually sees.

@t-matsudate
Copy link
Author

@t-matsudate did this happen again after you created the file?

Yes. Anytime but irregularly this matter happens.

@bjekt
Copy link

bjekt commented Jan 24, 2023

Ah, could this be related to autostore (i.e. emacs automated backups)?
It seems like the backup is created in the current directory, before being moved. Metals complains about it in lsp-log. Same for diffs I create (which are not real files). It does not happen every single time I save a file, but often enough.

@bjekt
Copy link

bjekt commented Jan 24, 2023

2023.01.24 15:29:31 ERROR Error encountered during file watchingjava.nio.file.NoSuchFileException: /Users/$user/$folder/.#Picklers.scala
	at sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)

@tgodzik
Copy link
Contributor

tgodzik commented Jan 24, 2023

@bjekt that might be the issue, we did some workarounds for it, but it's problematic to work with. It probably invokes the willRenameFiles which tries to inver package and infers it wrongly. So there are two issues:

  • inferring wrong package for the files (is there anything specific in your codebase)
  • treating the move as a file rename, maybe we could exclude emacs backups ?

@bjekt
Copy link

bjekt commented Jan 25, 2023

@tgodzik I managed to exclude the git diffs by modifying the
:hook (scala-mode . filterd-lsp)
instead of
:hook (scala-mode . lsp)
But it seems the autostore is picked up by the file watcher directly so maybe some way to filter there would be nice?
Are there any such filter available already?

@tgodzik
Copy link
Contributor

tgodzik commented Jan 25, 2023

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?

@bjekt
Copy link

bjekt commented Jan 25, 2023

It might be that #4891 will fix it.

For emacs it would probably be good to ignore the file names starting with .# i.e. myPackage/.#MyClass.scala

I tried building my own metals the other day to try to add some filter but hit some roadblocks so had to go back.

@ckipp01
Copy link
Member

ckipp01 commented Jan 25, 2023

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.

@tgodzik
Copy link
Contributor

tgodzik commented Jan 25, 2023

@bjekt are the files also readonly? Prefix plus .# plus readonly property should help use to identify the backup files.

@bjekt
Copy link

bjekt commented Jan 26, 2023

@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.
In the final location (i.e. ~/.emacs-backup for me) the files seems to be: -rw-r--r--

@bjekt
Copy link

bjekt commented Jan 26, 2023

#4904 This seems to fix it.

@bjekt
Copy link

bjekt commented Jan 26, 2023

Actually it did just kick in a bit later.

@bjekt
Copy link

bjekt commented Feb 3, 2023

src/main/scala/scala/meta/internal/metals/MetalsLanguageServer.scala:L2142

  @JsonRequest("workspace/willRenameFiles")
  def willRenameFiles(
      params: RenameFilesParams
  ): CompletableFuture[WorkspaceEdit] =
    CancelTokens.future { _ =>
      val moves = params.getFiles.asScala.toSeq.collect { 
        // ideally ignore if outside of workspace ? 
        case rename if ! rename.getNewUri().contains(".emacs-backups") =>
          packageProvider.willMovePath(
            rename.getOldUri().toAbsolutePath,
            rename.getNewUri().toAbsolutePath,
          )
      }
      Future.sequence(moves).map(_.mergeChanges)
    }

I still haven't been able to figure out why this move is being sent.

@tgodzik
Copy link
Contributor

tgodzik commented Feb 8, 2023

Are you able to figure out the rename.getOldUri().toAbsolutePath ? Is it the .# file?

@bjekt
Copy link

bjekt commented Feb 9, 2023

grafik
Yes, so it is when it creates the backup file. I check on moving a file out of the workspace would probably work, but maybe it should rather be fixed in lsp-mode ?

@tgodzik
Copy link
Contributor

tgodzik commented Feb 10, 2023

Let's see if #4967 helps

tgodzik added a commit to tgodzik/metals that referenced this issue Feb 10, 2023
@tgodzik
Copy link
Contributor

tgodzik commented Feb 13, 2023

@bjekt Are you able to check out 0.11.10+136-6952110f-SNAPSHOT ?

@bjekt
Copy link

bjekt commented Feb 13, 2023

Nice ! Looks good so far - I'll continue testing during the day.

grafik

Thanks a lot for this fix @tgodzik !

@t-matsudate
Copy link
Author

I'd like to check about changes in this snapshot. But I don't know how do I install this into Emacs.
Would you tell me how to install this?

@bjekt
Copy link

bjekt commented Feb 14, 2023

Hi @t-matsudate

coursier bootstrap \
  --java-opt -Xss4m \
  --java-opt -Xms100m \
  --java-opt -Dmetals.client=emacs \
  org.scalameta:metals_2.13:0.11.10+136-6952110f-SNAPSHOT \
  -r bintray:scalacenter/releases \
  -r sonatype:snapshots \
  -o /Users/myUser/bin/metals-emacs -f

You need to find the current location for your metals-emacs and replace the -o option accordingly.

@bjekt
Copy link

bjekt commented Feb 14, 2023

@tgodzik I had no issues yesterday. I think you nailed it!

@t-matsudate
Copy link
Author

@bjekt Thanks for your telling! Thanks to you, I could check that's fixed this issue. :)

@tgodzik Thank you for fixing this issue! Currently, I've found no more issues. Thanks to you, I'll use Metals with Emacs at ease! :)

@tgodzik
Copy link
Contributor

tgodzik commented Feb 14, 2023

Great to hear! Thanks for helping out with figuring the issue!

@tgodzik tgodzik closed this as completed Feb 14, 2023
@tgodzik tgodzik added this to the Metals v0.11.11 milestone Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants