Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Conversation

@Jarlakxen
Copy link
Contributor

Implemente #27. I putted some of the code in a companion object just to keep the ScalaLanguageClient class small.

@laughedelic
Copy link
Owner

laughedelic commented Feb 2, 2018

Hi @Jarlakxen. Is this a work in progress?

@Jarlakxen
Copy link
Contributor Author

Hi @laughedelic! The work is done for clearIndexCache and resetPresentationCompiler. I noticed a scalafixUnusedImports which is not mentioned in #27. Would you like to open a new issue? or I can try to do it all together.

@laughedelic
Copy link
Owner

Yes, it's better to add all available commands here. There's actually one more command: sbtConnect.

.gitignore Outdated

CHANGELOG.md
coursier
/bin/
Copy link
Owner

Choose a reason for hiding this comment

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

I'm just curious, what do you have there, why do you need to ignore it in every project?

}

override def postInitialization(server: ActiveServer): Unit = {
logger.debug(s"Server Capabilities:\n${js.JSON.stringify(server.capabilities, space = 2)}")
Copy link
Owner

Choose a reason for hiding this comment

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

Remove debug logging before merging, please. Btw, you can see it in the Atom logs anyway.

@laughedelic
Copy link
Owner

laughedelic commented Feb 2, 2018

I think that all this can be drastically simplified: once you got supportedCommands, you can just iterate over them and add each of them.

There's a bit tricky part about command names. See Atom docs:

Command names must follow the namespace:action pattern, where namespace will typically be the name of your package, and action describes the behavior of your command. If either part consists of multiple words, these must be separated by hyphens. E.g. awesome-package:turn-it-up-to-eleven. All words should be lowercased.

  • We should use either package name (ide-scala) or server name (metals) as the namespace prefix here (by the way, all this is specific to metals at the moment)
  • Command name has to be transformed from camelCase to snake-case (Atom will take care of formatting it nice for the command palette)

Here's a draft:

supportedCommands.foreach { cmd =>

  val cmdName = "[A-Z]".r.replaceAllIn(cmd, { "-" + _.group(0).toLowerCase() })

  Atom.commands.add("atom-text-editor", s"metals:${cmdName}", { _ => 
    server.connection.executeCommand(
      new ExecuteCommandParams(command = cmd)
    )
  })
}

@Jarlakxen what do you think about this approach?

@Jarlakxen
Copy link
Contributor Author

From what I understand that could work for clearIndexCache, resetPresentationCompiler and sbtConnect but not for scalafixUnusedImports. If that is correct, a solution could be define a whitelist of commands without special treatment like clearIndexCache, resetPresentationCompiler and sbtConnect and implement scalafixUnusedImports in other place.

@laughedelic
Copy link
Owner

I'm not sure I get it, why does scalafixUnusedImports need a special treatment?

@Jarlakxen
Copy link
Contributor Author

I saw this part of the code https://github.com/scalameta/metals/blob/master/metaserver/src/main/scala/scala/meta/languageserver/ScalametaServices.scala#L367 and OrganizeImports.removeUnused(params.arguments, symbolIndex) use params: ExecuteCommandParams. That arguments contains a TextDocumentIdentifier.
Maybe I didn't understand the functionality but from what I understand I need to pass a reference to the file from which I want to remove the unused imports.

@laughedelic
Copy link
Owner

I see. I think this is also solvable, but let's keep things simple for now and just skip this command:

  • the VS Code extension for metals doesn't have it either
  • you would normally use it through the code action, so it's won't be missing

Copy link
Owner

@laughedelic laughedelic left a comment

Choose a reason for hiding this comment

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

Looks fine, except the extra formatting changes. Could you revert them? I'm going to setup a scalafmt config later, so all code will have consistent formatting. Until then I'd like to keep PR changes to the minimum.

It's also strange that the CI is failing, I don't understand what is the problem.. 🤔

@laughedelic
Copy link
Owner

@Jarlakxen I just tried it out with the latest published server and it seems to work fine. At least I see that it receives the command request. Let's merge it!

@laughedelic laughedelic merged commit 5bd3be4 into laughedelic:master Feb 7, 2018
@laughedelic laughedelic mentioned this pull request Feb 10, 2018
@laughedelic laughedelic added this to the BIG release milestone Apr 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants