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

improvement: Don't sent text on didSave #7015

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tgodzik
Copy link
Contributor

@tgodzik tgodzik commented Dec 9, 2024

Previously, we would have clients send us full text on didSave, which was never used.

Now, we removed that option.

I also removed reading the file from disk to buffers since that file should already be up to date form didChanged

Previously, we would have clients send us full text on didSave, which was never used.

Now, we removed that option.

I also removed reading the file from disk to buffers since that file should already be up to date form didChanged
@@ -884,9 +884,6 @@ abstract class MetalsLspService(
): CompletableFuture[Unit] = {
val path = params.getTextDocument.getUri.toAbsolutePath
savedFiles.add(path)
// read file from disk, we only remove files from buffers on didClose.
val text = path.toInput.text
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem necessary and for large files might actually be problematic.

@tgodzik tgodzik force-pushed the did-save branch 3 times, most recently from 82ff17b to 9fd01d9 Compare December 10, 2024 14:26
@tgodzik tgodzik requested a review from kasiaMarek December 12, 2024 14:09
@tgodzik tgodzik marked this pull request as ready for review December 12, 2024 14:09
_ <- server.didChange(file)(_ =>
code.replaceAll(allMarkersRegex, "")
)
_ <- server.didSave(file)(identity)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should do either of two:

  • remove change function from server.didChange (it will always de identity)
  • have server.didSave with the function send first didChange and only later didSave.

_.replace("n + 1", "n + 2")
)
_ <- server.didSave("a/src/main/scala/a/Util.scala")(identity)
_ <- server.didFocus("a/src/main/scala/a/Main.worksheet.sc")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should ever need didFocus, since it may not be supported, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just focus switched to Util.scala and the worksheet doesn't evaluate. This will work in VS Code, thoguh wonder what happens if did focus is not supported

@@ -785,6 +785,7 @@ final case class TestingServer(
val abspath = toPath(filename)
val oldText = abspath.toInputFromBuffers(buffers).text
val newText = fn(oldText)
buffers.put(abspath, newText)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Comment on lines +887 to +889
if (!buffers.contains(path)) {
buffers.put(path, path.toInput.text)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!buffers.contains(path)) {
buffers.put(path, path.toInput.text)
}
buffers.putIfAbsent(path, path.toInput.text)

I think that buffers is based on a concurrent map (TrieMap), so maybe it would be safer to perform an atomic operation here, in case multiple requests are processed in parallel. 🙂

Also, a question to didSave and didChange: it looks like currently they always overwrite the in-memory buffers content for the given file, but in case of concurrent requests we could apply the older data (race condition)? Seems that the DidCloseTextDocumentParams should contain document version, could we use that to always safely keep only the newest one? Sorry if I have misunderstood how this all works. 🙂

Copy link
Contributor

@kasiaMarek kasiaMarek Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are very right. We want and we should use text document version simply nobody found the time to do it. I thought there was an issue for that but I could not find it now, here is a connected issue: #1665.

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

Successfully merging this pull request may close these issues.

3 participants