-
Notifications
You must be signed in to change notification settings - Fork 3
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
LSP support #54
Merged
LSP support #54
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ca4c68f
wip
kubukoz 599ba9f
Merge branch 'main' into lsp
kubukoz 24efca3
Initial support for formatting via LSP
kubukoz a994c66
Rename server class
kubukoz 4991230
error handling in formatter
kubukoz 64fdf30
Merge branch 'main' into lsp
kubukoz d230c5a
Clean up formatting support via LSP
kubukoz 74ffe0a
Bring back non-LSP functionality
kubukoz 234fcfe
Implement completions via LSP
kubukoz a738114
Remove js completions
kubukoz f679282
Move diagnostic code to core
kubukoz 1c2805b
Implement diagnostics in LSP
kubukoz 7604099
Move lenses to LSP
kubukoz ad415f1
Cleanup utils, add auth middleware to LSP client
kubukoz 69f93a2
Initial support for running via LSP + remove all extension customization
kubukoz 91499a5
cleanup
kubukoz 59ed8f9
Remove node dep
kubukoz a4d11ff
Fix parsing ranges
kubukoz a134f67
add todo
kubukoz 0154c4e
Cleanup
kubukoz 6abe585
Implement missing logs
kubukoz 7be57f5
Revamp configuration API
kubukoz 6b40e0b
Add custom extensions for output panel & command runner
kubukoz dd48631
Unhardcode workspace paths
kubukoz 8018181
Prepare for version/artifact replacement
kubukoz 7c38d9f
Drop scala.js
kubukoz 360b3d1
work on publishing
kubukoz 038dc76
Merge branch 'main' into lsp
kubukoz b136b14
run yarn first
kubukoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package playground | ||
|
||
import playground.smithyql.SourceRange | ||
import playground.smithyql.SmithyQLParser | ||
import cats.implicits._ | ||
import types._ | ||
|
||
trait CodeLensProvider[F[_]] { | ||
def provide(documentUri: String, documentText: String): List[CodeLens] | ||
} | ||
|
||
object CodeLensProvider { | ||
|
||
def instance[F[_]]( | ||
compiler: Compiler[IorThrow], | ||
runner: Runner.Optional[F], | ||
): CodeLensProvider[F] = | ||
new CodeLensProvider[F] { | ||
|
||
def provide(documentUri: String, documentText: String): List[CodeLens] = | ||
SmithyQLParser.parseFull(documentText) match { | ||
case Right(parsed) if runner.get(parsed).toEither.isRight => | ||
compiler | ||
.compile(parsed) | ||
.as { | ||
CodeLens( | ||
range = parsed.operationName.range, | ||
Command( | ||
title = "Run query", | ||
command = Command.RUN_QUERY, | ||
args = documentUri :: Nil, | ||
), | ||
) | ||
} | ||
.toList | ||
case _ => Nil | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
case class CodeLens(range: SourceRange, command: Command) | ||
case class Command(title: String, command: String, args: List[String]) | ||
|
||
object Command { | ||
val RUN_QUERY: String = "smithyql.runQuery" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package playground | ||
|
||
import cats.MonadThrow | ||
import cats.implicits._ | ||
import playground.smithyql.Formatter | ||
import playground.smithyql.InputNode | ||
import playground.smithyql.SmithyQLParser | ||
import playground.smithyql.WithSource | ||
|
||
import java.util.concurrent.atomic.AtomicInteger | ||
import scala.collection.immutable.ListMap | ||
|
||
trait Feedback[F[_]] { | ||
def showErrorMessage(msg: String): F[Unit] | ||
def showOutputPanel: F[Unit] | ||
def logOutput(msg: String): F[Unit] | ||
} | ||
|
||
object Feedback { | ||
def apply[F[_]](implicit F: Feedback[F]): Feedback[F] = F | ||
} | ||
|
||
trait CommandProvider[F[_]] { | ||
def runCommand(name: String, args: List[String]): F[Unit] | ||
} | ||
|
||
object CommandProvider { | ||
|
||
def instance[F[_]: MonadThrow: TextDocumentProvider: Feedback]( | ||
compiler: Compiler[F], | ||
runner: Runner.Optional[F], | ||
): CommandProvider[F] = | ||
new CommandProvider[F] { | ||
// todo mutability | ||
private val requestCount = new AtomicInteger(0) | ||
|
||
private def runQuery(documentUri: String): F[Unit] = TextDocumentProvider[F] | ||
.get(documentUri) | ||
.flatMap { documentText => | ||
SmithyQLParser | ||
.parseFull(documentText) | ||
.liftTo[F] | ||
.flatMap { parsed => | ||
runner | ||
.get(parsed) | ||
.toEither | ||
.leftMap(Runner.Issue.squash(_)) | ||
.leftMap { | ||
case Left(protocols) => | ||
Feedback[F].showErrorMessage( | ||
s"""The service uses an unsupported protocol. | ||
|Supported protocols: ${protocols | ||
.supported | ||
.map(_.show) | ||
.mkString_(", ")} | ||
|Found protocols: ${protocols | ||
.found | ||
.map(_.show) | ||
.mkString(", ")}""".stripMargin | ||
) | ||
|
||
case Right(others) => | ||
Feedback[F].showErrorMessage( | ||
others.map(_.toString).mkString_("\n\n") | ||
) | ||
} | ||
.map { runner => | ||
compiler | ||
.compile(parsed) | ||
.flatMap { compiled => | ||
val requestId = requestCount.addAndGet(1) | ||
|
||
Feedback[F].showOutputPanel *> | ||
Feedback[F].logOutput( | ||
s"// Calling ${parsed.operationName.value.text} ($requestId)" | ||
) *> | ||
runner | ||
.run(compiled) | ||
.onError { case e => | ||
val rendered = | ||
compiled | ||
.catchError(e) | ||
.flatMap(err => compiled.writeError.map(_.toNode(err))) match { | ||
case Some(e) => "\n" + writeOutput(e) | ||
case None => e.toString | ||
} | ||
|
||
Feedback[F].logOutput(s"// ERROR ($requestId) $rendered") | ||
} | ||
.flatMap { out => | ||
Feedback[F].logOutput( | ||
s"// Succeeded ${parsed.operationName.value.text} ($requestId), response:\n" | ||
+ writeOutput(out) | ||
) | ||
} | ||
} | ||
} | ||
.merge | ||
} | ||
} | ||
|
||
private def writeOutput( | ||
node: InputNode[cats.Id] | ||
) = Formatter.writeAst(node.mapK(WithSource.liftId)).renderTrim(80) | ||
|
||
private val commandMap: Map[String, List[String] => F[Unit]] = ListMap( | ||
Command.RUN_QUERY -> { | ||
case documentUri :: Nil => runQuery(documentUri) | ||
case s => new Throwable("Unsupported arguments: " + s).raiseError[F, Unit] | ||
} | ||
) | ||
|
||
def runCommand( | ||
name: String, | ||
args: List[String], | ||
): F[Unit] = commandMap | ||
.get(name) | ||
.liftTo[F](new Throwable("Unsupported command: " + name)) | ||
.flatMap(_.apply(args)) | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought I was gonna do the LSP in Scala 3, but I was getting too annoyed by the tooling.