diff --git a/README.md b/README.md new file mode 100644 index 0000000..8544ca8 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# PHP Language Server +> A pure PHP implementation of the [Language Server Protocol](https://github.com/Microsoft/language-server-protocol). + +[![Version](https://img.shields.io/packagist/v/felixfbecker/language-server.svg)]() [![License](https://img.shields.io/packagist/l/felixfbecker/language-server.svg)]() + diff --git a/src/Protocol/LanguageServer.php b/src/LanguageServer.php similarity index 100% rename from src/Protocol/LanguageServer.php rename to src/LanguageServer.php diff --git a/src/Protocol/CodeActionContext.php b/src/Protocol/CodeActionContext.php new file mode 100644 index 0000000..88e2e04 --- /dev/null +++ b/src/Protocol/CodeActionContext.php @@ -0,0 +1,17 @@ + LanguageServer\Protocol\Methods\TextDocument\DidOpenNotification + $class = __NAMESPACE__ . '\\Methods\\' . implode('\\', array_map('ucfirst', explode('/', $decoded->method))) . (isset($decoded->id) ? 'Request' : 'Notification'); + + // If the Request/Notification type is unknown, instantiate a basic Request or Notification class + // (this is the reason Request and Notification are not abstract) + if (!class_exists($class)) { + fwrite(STDERR, "Unknown method {$decoded->method}\n"); + if (!isset($decoded->id)) { + $class = Notification::class; + } else { + $class = $fallbackClass; + } + } + + // JsonMapper will take care of recursively using the right classes for $params etc. + $mapper = new JsonMapper(); + $message = $mapper->map($decoded, new $class); + + return $message; + } } diff --git a/src/Protocol/Methods/Window/MessageActionItem.php b/src/Protocol/MessageActionItem.php similarity index 65% rename from src/Protocol/Methods/Window/MessageActionItem.php rename to src/Protocol/MessageActionItem.php index 3dd276a..59dafe5 100644 --- a/src/Protocol/Methods/Window/MessageActionItem.php +++ b/src/Protocol/MessageActionItem.php @@ -1,8 +1,8 @@ emit($body->method, [$req]); $this->parsingMode = ParsingMode::HEADERS; $this->buffer = ''; diff --git a/src/Protocol/PublishDiagnosticParams.php b/src/Protocol/PublishDiagnosticParams.php index d81382c..c1180c7 100644 --- a/src/Protocol/PublishDiagnosticParams.php +++ b/src/Protocol/PublishDiagnosticParams.php @@ -1,8 +1,6 @@ id = $decoded->id; - $request->method = $decoded->method; - $pascalCasedMethod = ucfirst($decoded->method); - $namespace = __NAMESPACE__ . '\\' . str_replace('/', '\\', $pascalCasedMethod); - $className = end(explode('\\', $request->method)) . 'Params'; - $fullyQualifiedName = $namespace . $className; - $mapper->classMap['RequestParams'] = $fullyQualifiedName; - $request = $mapper->map(json_decode($body), new self()); - if (class_exists($fullyQualifiedName)) { - $request->params = new $fullyQualifiedName(); - } - foreach ($request->params as $key => $value) { - $request->{$key} = $value; - } - return $request; - } } diff --git a/src/Protocol/ResponseError.php b/src/Protocol/ResponseError.php index 134d955..3d0bd9e 100644 --- a/src/Protocol/ResponseError.php +++ b/src/Protocol/ResponseError.php @@ -1,5 +1,7 @@