364 changes: 324 additions & 40 deletions mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp

Large diffs are not rendered by default.

23 changes: 17 additions & 6 deletions mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ struct CompletionList;
struct DocumentLink;
struct DocumentSymbol;
struct Hover;
struct InlayHint;
struct Location;
struct Position;
struct Range;
struct SignatureHelp;
struct TextDocumentContentChangeEvent;
class URIForFile;

/// This class implements all of the PDLL related functionality necessary for a
Expand All @@ -50,12 +53,16 @@ class PDLLServer {
PDLLServer(const Options &options);
~PDLLServer();

/// Add or update the document, with the provided `version`, at the given URI.
/// Any diagnostics emitted for this document should be added to
/// `diagnostics`.
void addOrUpdateDocument(const URIForFile &uri, StringRef contents,
int64_t version,
std::vector<Diagnostic> &diagnostics);
/// Add the document, with the provided `version`, at the given URI. Any
/// diagnostics emitted for this document should be added to `diagnostics`.
void addDocument(const URIForFile &uri, StringRef contents, int64_t version,
std::vector<Diagnostic> &diagnostics);

/// Update the document, with the provided `version`, at the given URI. Any
/// diagnostics emitted for this document should be added to `diagnostics`.
void updateDocument(const URIForFile &uri,
ArrayRef<TextDocumentContentChangeEvent> changes,
int64_t version, std::vector<Diagnostic> &diagnostics);

/// Remove the document with the given uri. Returns the version of the removed
/// document, or None if the uri did not have a corresponding document within
Expand Down Expand Up @@ -90,6 +97,10 @@ class PDLLServer {
SignatureHelp getSignatureHelp(const URIForFile &uri,
const Position &helpPos);

/// Get the inlay hints for the range within the given file.
void getInlayHints(const URIForFile &uri, const Range &range,
std::vector<InlayHint> &inlayHints);

/// Get the output of the given PDLL file, or None if there is no valid
/// output.
Optional<PDLLViewOutputResult> getPDLLViewOutput(const URIForFile &uri,
Expand Down
16 changes: 5 additions & 11 deletions mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void LSPServer::onInitialize(const InitializeParams &params,
{"textDocumentSync",
llvm::json::Object{
{"openClose", true},
{"change", (int)TextDocumentSyncKind::Full},
{"change", (int)TextDocumentSyncKind::Incremental},
{"save", true},
}},
{"definitionProvider", true},
Expand Down Expand Up @@ -119,9 +119,8 @@ void LSPServer::onShutdown(const NoParams &, Callback<std::nullptr_t> reply) {
void LSPServer::onDocumentDidOpen(const DidOpenTextDocumentParams &params) {
PublishDiagnosticsParams diagParams(params.textDocument.uri,
params.textDocument.version);
server.addOrUpdateDocument(params.textDocument.uri, params.textDocument.text,
params.textDocument.version,
diagParams.diagnostics);
server.addDocument(params.textDocument.uri, params.textDocument.text,
params.textDocument.version, diagParams.diagnostics);

// Publish any recorded diagnostics.
publishDiagnostics(diagParams);
Expand All @@ -138,15 +137,10 @@ void LSPServer::onDocumentDidClose(const DidCloseTextDocumentParams &params) {
PublishDiagnosticsParams(params.textDocument.uri, *version));
}
void LSPServer::onDocumentDidChange(const DidChangeTextDocumentParams &params) {
// TODO: We currently only support full document updates, we should refactor
// to avoid this.
if (params.contentChanges.size() != 1)
return;
PublishDiagnosticsParams diagParams(params.textDocument.uri,
params.textDocument.version);
server.addOrUpdateDocument(
params.textDocument.uri, params.contentChanges.front().text,
params.textDocument.version, diagParams.diagnostics);
server.updateDocument(params.textDocument.uri, params.contentChanges,
params.textDocument.version, diagParams.diagnostics);

// Publish any recorded diagnostics.
publishDiagnostics(diagParams);
Expand Down
74 changes: 62 additions & 12 deletions mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "../lsp-server-support/Logging.h"
#include "../lsp-server-support/Protocol.h"
#include "../lsp-server-support/SourceMgrUtils.h"
#include "mlir/Support/LogicalResult.h"
#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/StringMap.h"
Expand Down Expand Up @@ -244,6 +245,12 @@ class TableGenTextFile {
/// Return the current version of this text file.
int64_t getVersion() const { return version; }

/// Update the file to the new version using the provided set of content
/// changes. Returns failure if the update was unsuccessful.
LogicalResult update(const lsp::URIForFile &uri, int64_t newVersion,
ArrayRef<lsp::TextDocumentContentChangeEvent> changes,
std::vector<lsp::Diagnostic> &diagnostics);

//===--------------------------------------------------------------------===//
// Definitions and References
//===--------------------------------------------------------------------===//
Expand All @@ -268,6 +275,10 @@ class TableGenTextFile {
const lsp::Position &hoverPos);

private:
/// Initialize the text file from the given file contents.
void initialize(const lsp::URIForFile &uri, int64_t newVersion,
std::vector<lsp::Diagnostic> &diagnostics);

/// The full string contents of the file.
std::string contents;

Expand All @@ -281,7 +292,7 @@ class TableGenTextFile {
llvm::SourceMgr sourceMgr;

/// The record keeper containing the parsed tablegen constructs.
llvm::RecordKeeper recordKeeper;
std::unique_ptr<llvm::RecordKeeper> recordKeeper;

/// The index of the parsed file.
TableGenIndex index;
Expand All @@ -296,19 +307,44 @@ TableGenTextFile::TableGenTextFile(
const std::vector<std::string> &extraIncludeDirs,
std::vector<lsp::Diagnostic> &diagnostics)
: contents(fileContents.str()), version(version) {
auto memBuffer = llvm::MemoryBuffer::getMemBufferCopy(contents, uri.file());
if (!memBuffer) {
lsp::Logger::error("Failed to create memory buffer for file", uri.file());
return;
}

// Build the set of include directories for this file.
llvm::SmallString<32> uriDirectory(uri.file());
llvm::sys::path::remove_filename(uriDirectory);
includeDirs.push_back(uriDirectory.str().str());
includeDirs.insert(includeDirs.end(), extraIncludeDirs.begin(),
extraIncludeDirs.end());

// Initialize the file.
initialize(uri, version, diagnostics);
}

LogicalResult
TableGenTextFile::update(const lsp::URIForFile &uri, int64_t newVersion,
ArrayRef<lsp::TextDocumentContentChangeEvent> changes,
std::vector<lsp::Diagnostic> &diagnostics) {
if (failed(lsp::TextDocumentContentChangeEvent::applyTo(changes, contents))) {
lsp::Logger::error("Failed to update contents of {0}", uri.file());
return failure();
}

// If the file contents were properly changed, reinitialize the text file.
initialize(uri, newVersion, diagnostics);
return success();
}

void TableGenTextFile::initialize(const lsp::URIForFile &uri,
int64_t newVersion,
std::vector<lsp::Diagnostic> &diagnostics) {
version = newVersion;
sourceMgr = llvm::SourceMgr();
recordKeeper = std::make_unique<llvm::RecordKeeper>();

// Build a buffer for this file.
auto memBuffer = llvm::MemoryBuffer::getMemBuffer(contents, uri.file());
if (!memBuffer) {
lsp::Logger::error("Failed to create memory buffer for file", uri.file());
return;
}
sourceMgr.setIncludeDirs(includeDirs);
sourceMgr.AddNewSourceBuffer(std::move(memBuffer), SMLoc());

Expand All @@ -327,15 +363,15 @@ TableGenTextFile::TableGenTextFile(
ctx->diagnostics.push_back(*lspDiag);
},
&handlerContext);
bool failedToParse = llvm::TableGenParseFile(sourceMgr, recordKeeper);
bool failedToParse = llvm::TableGenParseFile(sourceMgr, *recordKeeper);

// Process all of the include files.
lsp::gatherIncludeFiles(sourceMgr, parsedIncludes);
if (failedToParse)
return;

// If we successfully parsed the file, we can now build the index.
index.initialize(recordKeeper);
index.initialize(*recordKeeper);
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -417,9 +453,9 @@ lsp::TableGenServer::TableGenServer(const Options &options)
: impl(std::make_unique<Impl>(options)) {}
lsp::TableGenServer::~TableGenServer() = default;

void lsp::TableGenServer::addOrUpdateDocument(
const URIForFile &uri, StringRef contents, int64_t version,
std::vector<Diagnostic> &diagnostics) {
void lsp::TableGenServer::addDocument(const URIForFile &uri, StringRef contents,
int64_t version,
std::vector<Diagnostic> &diagnostics) {
// Build the set of additional include directories.
std::vector<std::string> additionalIncludeDirs = impl->options.extraDirs;
const auto &fileInfo = impl->compilationDatabase.getFileInfo(uri.file());
Expand All @@ -429,6 +465,20 @@ void lsp::TableGenServer::addOrUpdateDocument(
uri, contents, version, additionalIncludeDirs, diagnostics);
}

void lsp::TableGenServer::updateDocument(
const URIForFile &uri, ArrayRef<TextDocumentContentChangeEvent> changes,
int64_t version, std::vector<Diagnostic> &diagnostics) {
// Check that we actually have a document for this uri.
auto it = impl->files.find(uri.file());
if (it == impl->files.end())
return;

// Try to update the document. If we fail, erase the file from the server. A
// failed updated generally means we've fallen out of sync somewhere.
if (failed(it->second->update(uri, version, changes, diagnostics)))
impl->files.erase(it);
}

Optional<int64_t> lsp::TableGenServer::removeDocument(const URIForFile &uri) {
auto it = impl->files.find(uri.file());
if (it == impl->files.end())
Expand Down
17 changes: 11 additions & 6 deletions mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct DocumentLink;
struct Hover;
struct Location;
struct Position;
struct TextDocumentContentChangeEvent;
class URIForFile;

/// This class implements all of the TableGen related functionality necessary
Expand All @@ -44,12 +45,16 @@ class TableGenServer {
TableGenServer(const Options &options);
~TableGenServer();

/// Add or update the document, with the provided `version`, at the given URI.
/// Any diagnostics emitted for this document should be added to
/// `diagnostics`.
void addOrUpdateDocument(const URIForFile &uri, StringRef contents,
int64_t version,
std::vector<Diagnostic> &diagnostics);
/// Add the document, with the provided `version`, at the given URI. Any
/// diagnostics emitted for this document should be added to `diagnostics`.
void addDocument(const URIForFile &uri, StringRef contents, int64_t version,
std::vector<Diagnostic> &diagnostics);

/// Update the document, with the provided `version`, at the given URI. Any
/// diagnostics emitted for this document should be added to `diagnostics`.
void updateDocument(const URIForFile &uri,
ArrayRef<TextDocumentContentChangeEvent> changes,
int64_t version, std::vector<Diagnostic> &diagnostics);

/// Remove the document with the given uri. Returns the version of the removed
/// document, or None if the uri did not have a corresponding document within
Expand Down
3 changes: 2 additions & 1 deletion mlir/test/mlir-pdll-lsp-server/initialize-params.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// CHECK-NEXT: },
// CHECK-NEXT: "documentSymbolProvider": true,
// CHECK-NEXT: "hoverProvider": true,
// CHECK-NEXT: "inlayHintProvider": true,
// CHECK-NEXT: "referencesProvider": true,
// CHECK-NEXT: "signatureHelpProvider": {
// CHECK-NEXT: "triggerCharacters": [
Expand All @@ -26,7 +27,7 @@
// CHECK-NEXT: ]
// CHECK-NEXT: },
// CHECK-NEXT: "textDocumentSync": {
// CHECK-NEXT: "change": 1,
// CHECK-NEXT: "change": 2,
// CHECK-NEXT: "openClose": true,
// CHECK-NEXT: "save": true
// CHECK-NEXT: }
Expand Down
107 changes: 107 additions & 0 deletions mlir/test/mlir-pdll-lsp-server/inlay-hints.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// RUN: mlir-pdll-lsp-server -pdll-extra-dir %S -pdll-extra-dir %S/../../include -lit-test < %s | FileCheck -strict-whitespace %s
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"pdll","capabilities":{},"trace":"off"}}
// -----
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{
"uri":"test:///foo.pdll",
"languageId":"pdll",
"version":1,
"text":"#include \"include/included.td\"\nConstraint Cst(attr: Attr);\nPattern {\n op<test.multi>(_: Value, _: Value);\n op<test.multi>(_: ValueRange) -> (_: Type, _: Type);\n let op = op<test.multi>;\n let value = op.0;\n Cst(_: Attr);\n erase op;\n}\n"
}}}
// -----
{"jsonrpc":"2.0","id":2,"method":"textDocument/inlayHint","params":{
"textDocument":{"uri":"test:///foo.pdll"},
"range": {
"start": {"line":3,"character":0},
"end": {"line":5,"character":0}
}
}}
// CHECK: "id": 2,
// CHECK-NEXT: "jsonrpc": "2.0",
// CHECK-NEXT: "result": [
// CHECK-NEXT: {
// CHECK-NEXT: "kind": 2,
// CHECK-NEXT: "label": "operand:",
// CHECK-NEXT: "paddingLeft": false,
// CHECK-NEXT: "paddingRight": true,
// CHECK-NEXT: "position": {
// CHECK-NEXT: "character": 17,
// CHECK-NEXT: "line": 3
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": 2,
// CHECK-NEXT: "label": "operand2:",
// CHECK-NEXT: "paddingLeft": false,
// CHECK-NEXT: "paddingRight": true,
// CHECK-NEXT: "position": {
// CHECK-NEXT: "character": 27,
// CHECK-NEXT: "line": 3
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": 2,
// CHECK-NEXT: "label": "operands:",
// CHECK-NEXT: "paddingLeft": false,
// CHECK-NEXT: "paddingRight": true,
// CHECK-NEXT: "position": {
// CHECK-NEXT: "character": 17,
// CHECK-NEXT: "line": 4
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": 2,
// CHECK-NEXT: "label": "result:",
// CHECK-NEXT: "paddingLeft": false,
// CHECK-NEXT: "paddingRight": true,
// CHECK-NEXT: "position": {
// CHECK-NEXT: "character": 36,
// CHECK-NEXT: "line": 4
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": 2,
// CHECK-NEXT: "label": "result2:",
// CHECK-NEXT: "paddingLeft": false,
// CHECK-NEXT: "paddingRight": true,
// CHECK-NEXT: "position": {
// CHECK-NEXT: "character": 45,
// CHECK-NEXT: "line": 4
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ]
// -----
{"jsonrpc":"2.0","id":3,"method":"textDocument/inlayHint","params":{
"textDocument":{"uri":"test:///foo.pdll"},
"range": {
"start": {"line":5,"character":0},
"end": {"line":8,"character":0}
}
}}
// CHECK: "id": 3,
// CHECK-NEXT: "jsonrpc": "2.0",
// CHECK-NEXT: "result": [
// CHECK-NEXT: {
// CHECK-NEXT: "kind": 1,
// CHECK-NEXT: "label": ": Value",
// CHECK-NEXT: "paddingLeft": false,
// CHECK-NEXT: "paddingRight": false,
// CHECK-NEXT: "position": {
// CHECK-NEXT: "character": 11,
// CHECK-NEXT: "line": 6
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": 2,
// CHECK-NEXT: "label": "attr:",
// CHECK-NEXT: "paddingLeft": false,
// CHECK-NEXT: "paddingRight": true,
// CHECK-NEXT: "position": {
// CHECK-NEXT: "character": 6,
// CHECK-NEXT: "line": 7
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ]
// -----
{"jsonrpc":"2.0","id":4,"method":"shutdown"}
// -----
{"jsonrpc":"2.0","method":"exit"}
96 changes: 96 additions & 0 deletions mlir/test/mlir-pdll-lsp-server/textdocument-didchange.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// RUN: mlir-pdll-lsp-server -lit-test < %s | FileCheck -strict-whitespace %s
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"pdll","capabilities":{},"trace":"off"}}
// -----
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{
"uri":"test:///foo.pdll",
"languageId":"pdll",
"version":1,
"text":"Pattern => replace with ;"
}}}
// CHECK: "method": "textDocument/publishDiagnostics",
// CHECK-NEXT: "params": {
// CHECK-NEXT: "diagnostics": [
// CHECK-NEXT: {
// CHECK-NEXT: "category": "Parse Error",
// CHECK-NEXT: "message": "expected expression",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "end": {
// CHECK-NEXT: "character": 23,
// CHECK-NEXT: "line": 0
// CHECK-NEXT: },
// CHECK-NEXT: "start": {
// CHECK-NEXT: "character": 19,
// CHECK-NEXT: "line": 0
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "severity": 1,
// CHECK-NEXT: "source": "pdll"
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "uri": "test:///foo.pdll",
// CHECK-NEXT: "version": 1
// CHECK-NEXT: }
// -----
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{
"uri":"test:///foo.pdll",
"version":2
}, "contentChanges": [{
"range":{
"start":{"line":0,"character":18},
"end":{"line":0,"character":18}
},
"text": " op<test.op>"
}]}}
// CHECK: "method": "textDocument/publishDiagnostics",
// CHECK-NEXT: "params": {
// CHECK-NEXT: "diagnostics": [
// CHECK-NEXT: {
// CHECK-NEXT: "category": "Parse Error",
// CHECK-NEXT: "message": "expected expression",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "end": {
// CHECK-NEXT: "character": 37,
// CHECK-NEXT: "line": 0
// CHECK-NEXT: },
// CHECK-NEXT: "start": {
// CHECK-NEXT: "character": 36,
// CHECK-NEXT: "line": 0
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "severity": 1,
// CHECK-NEXT: "source": "pdll"
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "uri": "test:///foo.pdll",
// CHECK-NEXT: "version": 2
// CHECK-NEXT: }
// -----
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{
"uri":"test:///foo.pdll",
"version":3
}, "contentChanges": [
{
"range":{
"start":{"line":0,"character":30},
"end":{"line":0,"character":30}
},
"text": "(values: ValueRange)"
},
{
"range":{
"start":{"line":0,"character":56},
"end":{"line":0,"character":57}
},
"text": "values;"
}
]}}
// CHECK: "method": "textDocument/publishDiagnostics",
// CHECK-NEXT: "params": {
// CHECK-NEXT: "diagnostics": [],
// CHECK-NEXT: "uri": "test:///foo.pdll",
// CHECK-NEXT: "version": 3
// CHECK-NEXT: }
// -----
{"jsonrpc":"2.0","id":3,"method":"shutdown"}
// -----
{"jsonrpc":"2.0","method":"exit"}
2 changes: 1 addition & 1 deletion mlir/test/tblgen-lsp-server/initialize-params.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// CHECK-NEXT: "hoverProvider": true,
// CHECK-NEXT: "referencesProvider": true,
// CHECK-NEXT: "textDocumentSync": {
// CHECK-NEXT: "change": 1,
// CHECK-NEXT: "change": 2,
// CHECK-NEXT: "openClose": true,
// CHECK-NEXT: "save": true
// CHECK-NEXT: }
Expand Down
96 changes: 96 additions & 0 deletions mlir/test/tblgen-lsp-server/textdocument-didchange.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// RUN: tblgen-lsp-server -lit-test < %s | FileCheck -strict-whitespace %s
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"tablegen","capabilities":{},"trace":"off"}}
// -----
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{
"uri":"test:///foo.td",
"languageId":"tablegen",
"version":1,
"text":"class Foo<>;"
}}}
// CHECK: "method": "textDocument/publishDiagnostics",
// CHECK-NEXT: "params": {
// CHECK-NEXT: "diagnostics": [
// CHECK-NEXT: {
// CHECK-NEXT: "category": "Parse Error",
// CHECK-NEXT: "message": "Unknown token when expecting a type",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "end": {
// CHECK-NEXT: "character": 11,
// CHECK-NEXT: "line": 0
// CHECK-NEXT: },
// CHECK-NEXT: "start": {
// CHECK-NEXT: "character": 10,
// CHECK-NEXT: "line": 0
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "severity": 1,
// CHECK-NEXT: "source": "tablegen"
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "uri": "test:///foo.td",
// CHECK-NEXT: "version": 1
// CHECK-NEXT: }
// -----
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{
"uri":"test:///foo.td",
"version":2
}, "contentChanges": [{
"range":{
"start":{"line":0,"character":10},
"end":{"line":0,"character":10}
},
"text": "int"
}]}}
// CHECK: "method": "textDocument/publishDiagnostics",
// CHECK-NEXT: "params": {
// CHECK-NEXT: "diagnostics": [
// CHECK-NEXT: {
// CHECK-NEXT: "category": "Parse Error",
// CHECK-NEXT: "message": "Expected identifier in declaration",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "end": {
// CHECK-NEXT: "character": 14,
// CHECK-NEXT: "line": 0
// CHECK-NEXT: },
// CHECK-NEXT: "start": {
// CHECK-NEXT: "character": 13,
// CHECK-NEXT: "line": 0
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "severity": 1,
// CHECK-NEXT: "source": "tablegen"
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "uri": "test:///foo.td",
// CHECK-NEXT: "version": 2
// CHECK-NEXT: }
// -----
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{
"uri":"test:///foo.td",
"version":3
}, "contentChanges": [
{
"range":{
"start":{"line":0,"character":13},
"end":{"line":0,"character":13}
},
"text": " i"
},
{
"range":{
"start":{"line":0,"character":15},
"end":{"line":0,"character":17}
},
"text": "> { int x = i; }"
}
]}}
// CHECK: "method": "textDocument/publishDiagnostics",
// CHECK-NEXT: "params": {
// CHECK-NEXT: "diagnostics": [],
// CHECK-NEXT: "uri": "test:///foo.td",
// CHECK-NEXT: "version": 3
// CHECK-NEXT: }
// -----
{"jsonrpc":"2.0","id":3,"method":"shutdown"}
// -----
{"jsonrpc":"2.0","method":"exit"}
1,676 changes: 1,205 additions & 471 deletions mlir/utils/vscode/package-lock.json

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions mlir/utils/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "vscode-mlir",
"displayName": "MLIR",
"description": "MLIR Language Extension",
"version": "0.0.8",
"version": "0.0.9",
"publisher": "llvm-vs-code-extensions",
"homepage": "https://mlir.llvm.org/",
"icon": "icon.png",
"engines": {
"vscode": "^1.52.0"
"vscode": "^1.67.0"
},
"categories": [
"Programming Languages"
Expand Down Expand Up @@ -36,17 +36,15 @@
},
"dependencies": {
"chokidar": "3.5.2",
"vscode-languageclient": "^5.2.1",
"vscode-languageserver-types": "3.16.0"
"vscode-languageclient": "^8.0.1"
},
"devDependencies": {
"@types/mocha": "^5.2.0",
"@types/node": "^8.0.0",
"@types/vscode": "1.52.*",
"clang-format": "1.4.0",
"tslint": "^5.16.0",
"typescript": "^3.5.1",
"vsce": "^1.75.0",
"@types/mocha": "^7.0.2",
"@types/node": "^14.17.0",
"@types/vscode": "~1.67.0",
"clang-format": "^1.8.0",
"typescript": "^4.6.4",
"vsce": "^2.7.0",
"vscode-test": "^1.3.0"
},
"repository": {
Expand Down
21 changes: 8 additions & 13 deletions mlir/utils/vscode/src/mlirContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
import * as vscodelc from 'vscode-languageclient';
import * as vscodelc from 'vscode-languageclient/node';

import * as config from './config';
import * as configWatcher from './configWatcher';
Expand All @@ -11,7 +11,7 @@ import * as configWatcher from './configWatcher';
*/
class WorkspaceFolderContext implements vscode.Disposable {
dispose() {
this.clients.forEach(client => client.stop());
this.clients.forEach(async client => await client.stop());
this.clients.clear();
}

Expand Down Expand Up @@ -229,16 +229,8 @@ export class MLIRContext implements vscode.Disposable {

// Configure the server options.
const serverOptions: vscodelc.ServerOptions = {
run : {
command : serverPath,
transport : vscodelc.TransportKind.stdio,
args : additionalServerArgs
},
debug : {
command : serverPath,
transport : vscodelc.TransportKind.stdio,
args : additionalServerArgs
}
command : serverPath,
args : additionalServerArgs
};

// Configure file patterns relative to the workspace folder.
Expand Down Expand Up @@ -279,7 +271,10 @@ export class MLIRContext implements vscode.Disposable {
},
outputChannel : outputChannel,
workspaceFolder : workspaceFolder,
middleware : middleware
middleware : middleware,

// Don't switch to output window when the server returns output.
revealOutputChannelOn : vscodelc.RevealOutputChannelOn.Never,
};

// Create the language client and start the client.
Expand Down