summaryrefslogtreecommitdiffstats
path: root/source/compiler-core
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-06-27 15:36:00 -0700
committerGitHub <noreply@github.com>2022-06-27 15:36:00 -0700
commitb7638b8fffe78ade657f361cadc08dffc8c10acf (patch)
treee27a141cfc6a9cc77356b8cba27b41c495d4ee27 /source/compiler-core
parent62d16a23b0ecd72dc624abd7e10b373c40adaa90 (diff)
Language server fixes and improvements (#2304)
* Language server: Inlay hints. * Signature help for base exprs that is not a declref. * Fix checking of jvp operator. * Fix. * Add clang-format based auto formatting. * Fix clang error. * Fix clang-format discovery logic. * Fine tune auto formatting and completion experience. * Update macos workflow. * Fixes to configurations. * Fix parser recovery to trigger completion for index exprs. * Typo fix. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/compiler-core')
-rw-r--r--source/compiler-core/slang-language-server-protocol.cpp118
-rw-r--r--source/compiler-core/slang-language-server-protocol.h242
-rw-r--r--source/compiler-core/slang-lexer.cpp7
3 files changed, 361 insertions, 6 deletions
diff --git a/source/compiler-core/slang-language-server-protocol.cpp b/source/compiler-core/slang-language-server-protocol.cpp
index 51799f05e..d2950b164 100644
--- a/source/compiler-core/slang-language-server-protocol.cpp
+++ b/source/compiler-core/slang-language-server-protocol.cpp
@@ -25,6 +25,27 @@ static const StructRttiInfo _makeWorkDoneProgressParamsRtti()
}
const StructRttiInfo WorkDoneProgressParams::g_rttiInfo = _makeWorkDoneProgressParamsRtti();
+static const StructRttiInfo _makeInlayHintOptionsRtti()
+{
+ InlayHintOptions obj;
+ StructRttiBuilder builder(&obj, "LanguageServerProtocol::InlayHintOptions", nullptr);
+ builder.addField("resolveProvider", &obj.resolveProvider);
+ builder.ignoreUnknownFields();
+ return builder.make();
+}
+const StructRttiInfo InlayHintOptions::g_rttiInfo = _makeInlayHintOptionsRtti();
+
+static const StructRttiInfo _makeDocumentOnTypeFormattingOptionsRtti()
+{
+ DocumentOnTypeFormattingOptions obj;
+ StructRttiBuilder builder(&obj, "LanguageServerProtocol::DocumentOnTypeFormattingOptions", nullptr);
+ builder.addField("firstTriggerCharacter", &obj.firstTriggerCharacter);
+ builder.addField("moreTriggerCharacter", &obj.moreTriggerCharacter);
+ builder.ignoreUnknownFields();
+ return builder.make();
+}
+const StructRttiInfo DocumentOnTypeFormattingOptions::g_rttiInfo = _makeDocumentOnTypeFormattingOptionsRtti();
+
static const StructRttiInfo _makeCompletionOptionsRtti()
{
CompletionOptions obj;
@@ -211,6 +232,10 @@ static const StructRttiInfo _makeServerCapabilitiesRtti()
builder.addField("textDocumentSync", &obj.textDocumentSync);
builder.addField("workspace", &obj.workspace);
builder.addField("hoverProvider", &obj.hoverProvider);
+ builder.addField("inlayHintProvider", &obj.inlayHintProvider);
+ builder.addField("documentOnTypeFormattingProvider", &obj.documentOnTypeFormattingProvider);
+ builder.addField("documentFormattingProvider", &obj.documentFormattingProvider);
+ builder.addField("documentRangeFormattingProvider", &obj.documentRangeFormattingProvider);
builder.addField("definitionProvider", &obj.definitionProvider);
builder.addField("completionProvider", &obj.completionProvider);
builder.addField("semanticTokensProvider", &obj.semanticTokensProvider);
@@ -382,6 +407,17 @@ static const StructRttiInfo _makeHoverRtti()
}
const StructRttiInfo Hover::g_rttiInfo = _makeHoverRtti();
+static const StructRttiInfo _makeCompletionContextRtti()
+{
+ CompletionContext obj;
+ StructRttiBuilder builder(&obj, "LanguageServerProtocol::CompletionContext", nullptr);
+ builder.addField("triggerKind", &obj.triggerKind);
+ builder.addField("triggerCharacter", &obj.triggerCharacter, StructRttiInfo::Flag::Optional);
+ builder.ignoreUnknownFields();
+ return builder.make();
+}
+const StructRttiInfo CompletionContext::g_rttiInfo = _makeCompletionContextRtti();
+
static const StructRttiInfo _makeDefinitionParamsRtti()
{
DefinitionParams obj;
@@ -401,6 +437,7 @@ static const StructRttiInfo _makeCompletionParamsRtti()
StructRttiBuilder builder(&obj, "LanguageServerProtocol::CompletionParams", &WorkDoneProgressParams::g_rttiInfo);
builder.addField("textDocument", &obj.textDocument);
builder.addField("position", &obj.position);
+ builder.addField("context", &obj.context, StructRttiInfo::Flag::Optional);
builder.ignoreUnknownFields();
return builder.make();
}
@@ -604,6 +641,87 @@ static const StructRttiInfo _makeDocumentSymbolRtti()
}
const StructRttiInfo DocumentSymbol::g_rttiInfo = _makeDocumentSymbolRtti();
+static const StructRttiInfo _makeTextEditRtti()
+{
+ TextEdit obj;
+ StructRttiBuilder builder(&obj, "LanguageServerProtocol::TextEdit", nullptr);
+ builder.addField("range", &obj.range);
+ builder.addField("newText", &obj.newText);
+ builder.ignoreUnknownFields();
+ return builder.make();
+}
+const StructRttiInfo TextEdit::g_rttiInfo = _makeTextEditRtti();
+
+static const StructRttiInfo _makeInlayHintParamsRtti()
+{
+ InlayHintParams obj;
+ StructRttiBuilder builder(
+ &obj, "LanguageServerProtocol::InlayHintParams", nullptr);
+ builder.addField("range", &obj.range);
+ builder.addField("textDocument", &obj.textDocument);
+ builder.ignoreUnknownFields();
+ return builder.make();
+}
+const StructRttiInfo InlayHintParams::g_rttiInfo = _makeInlayHintParamsRtti();
+const UnownedStringSlice InlayHintParams::methodName =
+ UnownedStringSlice::fromLiteral("textDocument/inlayHint");
+
+static const StructRttiInfo _makeInlayHintRtti()
+{
+ InlayHint obj;
+ StructRttiBuilder builder(
+ &obj, "LanguageServerProtocol::InlayHint", nullptr);
+ builder.addField("position", &obj.position);
+ builder.addField("label", &obj.label);
+ builder.addField("kind", &obj.kind);
+ builder.addField("paddingLeft", &obj.paddingLeft);
+ builder.addField("paddingRight", &obj.paddingRight);
+ builder.addField("textEdits", &obj.textEdits);
+
+ builder.ignoreUnknownFields();
+ return builder.make();
+}
+const StructRttiInfo InlayHint::g_rttiInfo = _makeInlayHintRtti();
+
+static const StructRttiInfo _makeDocumentFormattingParamsRtti()
+{
+ DocumentFormattingParams obj;
+ StructRttiBuilder builder(&obj, "LanguageServerProtocol::DocumentFormattingParams", nullptr);
+ builder.addField("textDocument", &obj.textDocument);
+ builder.ignoreUnknownFields();
+ return builder.make();
+}
+const StructRttiInfo DocumentFormattingParams::g_rttiInfo = _makeDocumentFormattingParamsRtti();
+const UnownedStringSlice DocumentFormattingParams::methodName =
+ UnownedStringSlice::fromLiteral("textDocument/formatting");
+
+static const StructRttiInfo _makeDocumentRangeFormattingParamsRtti()
+{
+ DocumentRangeFormattingParams obj;
+ StructRttiBuilder builder(&obj, "LanguageServerProtocol::DocumentRangeFormattingParams", nullptr);
+ builder.addField("textDocument", &obj.textDocument);
+ builder.addField("range", &obj.range);
+ builder.ignoreUnknownFields();
+ return builder.make();
+}
+const StructRttiInfo DocumentRangeFormattingParams::g_rttiInfo = _makeDocumentRangeFormattingParamsRtti();
+const UnownedStringSlice DocumentRangeFormattingParams::methodName =
+ UnownedStringSlice::fromLiteral("textDocument/rangeFormatting");
+
+static const StructRttiInfo _makeDocumentOnTypeFormattingParamsRtti()
+{
+ DocumentOnTypeFormattingParams obj;
+ StructRttiBuilder builder(&obj, "LanguageServerProtocol::DocumentOnTypeFormattingParams", nullptr);
+ builder.addField("textDocument", &obj.textDocument);
+ builder.addField("position", &obj.position);
+ builder.addField("ch", &obj.ch);
+ builder.ignoreUnknownFields();
+ return builder.make();
+}
+const StructRttiInfo DocumentOnTypeFormattingParams::g_rttiInfo = _makeDocumentOnTypeFormattingParamsRtti();
+const UnownedStringSlice DocumentOnTypeFormattingParams::methodName =
+ UnownedStringSlice::fromLiteral("textDocument/onTypeFormatting");
+
} // namespace LanguageServerProtocol
}
diff --git a/source/compiler-core/slang-language-server-protocol.h b/source/compiler-core/slang-language-server-protocol.h
index 7d9d8d5cb..fbc79acca 100644
--- a/source/compiler-core/slang-language-server-protocol.h
+++ b/source/compiler-core/slang-language-server-protocol.h
@@ -232,6 +232,37 @@ struct WorkspaceCapabilities
static const StructRttiInfo g_rttiInfo;
};
+/**
+ * Inlay hint options used during static registration.
+ *
+ * @since 3.17.0
+ */
+struct InlayHintOptions
+{
+ /**
+ * The server provides support to resolve additional
+ * information for an inlay hint item.
+ */
+ bool resolveProvider = false;
+ static const StructRttiInfo g_rttiInfo;
+
+};
+
+struct DocumentOnTypeFormattingOptions
+{
+ /**
+ * A character on which formatting should be triggered, like `{`.
+ */
+ String firstTriggerCharacter;
+
+ /**
+ * More trigger characters.
+ */
+ List<String> moreTriggerCharacter;
+
+ static const StructRttiInfo g_rttiInfo;
+};
+
struct ServerCapabilities
{
String positionEncoding;
@@ -239,6 +270,10 @@ struct ServerCapabilities
bool hoverProvider = false;
bool definitionProvider = false;
bool documentSymbolProvider = false;
+ bool documentFormattingProvider = false;
+ bool documentRangeFormattingProvider = false;
+ DocumentOnTypeFormattingOptions documentOnTypeFormattingProvider;
+ InlayHintOptions inlayHintProvider;
CompletionOptions completionProvider;
SemanticTokensOptions semanticTokensProvider;
SignatureHelpOptions signatureHelpProvider;
@@ -336,7 +371,7 @@ struct Diagnostic
* The diagnostic's severity. Can be omitted. If omitted it is up to the
* client to interpret diagnostics as error, warning, info or hint.
*/
- DiagnosticSeverity severity;
+ DiagnosticSeverity severity = 1;
/**
* The diagnostic's code, which might appear in the user interface.
@@ -452,10 +487,48 @@ struct Hover
static const StructRttiInfo g_rttiInfo;
};
+typedef int CompletionTriggerKind;
+const CompletionTriggerKind kCompletionTriggerKindInvoked = 1;
+
+/**
+ * Completion was triggered by a trigger character specified by
+ * the `triggerCharacters` properties of the
+ * `CompletionRegistrationOptions`.
+ */
+const CompletionTriggerKind kCompletionTriggerKindTriggerCharacter = 2;
+
+/**
+ * Completion was re-triggered as the current completion list is incomplete.
+ */
+const CompletionTriggerKind kCompletionTriggerKindTriggerForIncompleteCompletions = 3;
+
+/**
+ * Contains additional information about the context in which a completion
+ * request is triggered.
+ */
+struct CompletionContext
+{
+ /**
+ * How the completion was triggered.
+ */
+ CompletionTriggerKind triggerKind = 1;
+
+ /**
+ * The trigger character (a single character) that has trigger code
+ * complete. Is undefined if
+ * `triggerKind !== CompletionTriggerKind.TriggerCharacter`
+ */
+ String triggerCharacter;
+
+ static const StructRttiInfo g_rttiInfo;
+};
+
struct CompletionParams
: WorkDoneProgressParams
, TextDocumentPositionParams
{
+ CompletionContext context;
+
static const StructRttiInfo g_rttiInfo;
static const UnownedStringSlice methodName;
};
@@ -786,8 +859,8 @@ const int kSymbolKindTypeParameter = 26;
* have two ranges: one that encloses its definition and one that points to its
* most interesting range, e.g. the range of an identifier.
*/
-struct DocumentSymbol {
-
+struct DocumentSymbol
+{
/**
* The name of this symbol. Will be displayed in the user interface and
* therefore must not be an empty string or a string only consisting of
@@ -803,7 +876,7 @@ struct DocumentSymbol {
/**
* The kind of this symbol.
*/
- SymbolKind kind;
+ SymbolKind kind = 0;
/**
* The range enclosing this symbol not including leading/trailing whitespace
@@ -827,5 +900,166 @@ struct DocumentSymbol {
static const StructRttiInfo g_rttiInfo;
};
+/**
+ * A parameter literal used in inlay hint requests.
+ *
+ * @since 3.17.0
+ */
+struct InlayHintParams
+{
+ /**
+ * The text document.
+ */
+ TextDocumentIdentifier textDocument;
+
+ /**
+ * The visible document range for which inlay hints should be computed.
+ */
+ Range range;
+
+ static const StructRttiInfo g_rttiInfo;
+ static const UnownedStringSlice methodName;
+};
+
+struct TextEdit
+{
+ /**
+ * The range of the text document to be manipulated. To insert
+ * text into a document create a range where start === end.
+ */
+ Range range;
+
+ /**
+ * The string to be inserted. For delete operations use an
+ * empty string.
+ */
+ String newText;
+
+ static const StructRttiInfo g_rttiInfo;
+
+};
+
+typedef int InlayHintKind;
+const int kInlayHintKindType = 1;
+const int kInlayHintKindParameter = 2;
+
+/**
+ * Inlay hint information.
+ *
+ * @since 3.17.0
+ */
+struct InlayHint
+{
+ /**
+ * The position of this hint.
+ */
+ Position position;
+
+ /**
+ * The label of this hint. A human readable string or an array of
+ * InlayHintLabelPart label parts.
+ *
+ * *Note* that neither the string nor the label part can be empty.
+ */
+ String label;
+
+ /**
+ * The kind of this hint. Can be omitted in which case the client
+ * should fall back to a reasonable default.
+ */
+ InlayHintKind kind = 1;
+
+ List<TextEdit> textEdits;
+
+ /**
+ * Render padding before the hint.
+ *
+ * Note: Padding should use the editor's background color, not the
+ * background color of the hint itself. That means padding can be used
+ * to visually align/separate an inlay hint.
+ */
+ bool paddingLeft = false;
+
+ /**
+ * Render padding after the hint.
+ *
+ * Note: Padding should use the editor's background color, not the
+ * background color of the hint itself. That means padding can be used
+ * to visually align/separate an inlay hint.
+ */
+ bool paddingRight = false;
+
+ static const StructRttiInfo g_rttiInfo;
+
+};
+
+struct DocumentOnTypeFormattingParams
+{
+ /**
+ * The document to format.
+ */
+ TextDocumentIdentifier textDocument;
+
+ /**
+ * The position around which the on type formatting should happen.
+ * This is not necessarily the exact position where the character denoted
+ * by the property `ch` got typed.
+ */
+ Position position;
+
+ /**
+ * The character that has been typed that triggered the formatting
+ * on type request. That is not necessarily the last character that
+ * got inserted into the document since the client could auto insert
+ * characters as well (e.g. like automatic brace completion).
+ */
+ String ch;
+
+ /**
+ * The formatting options.
+ */
+ //FormattingOptions options;
+
+ static const StructRttiInfo g_rttiInfo;
+ static const UnownedStringSlice methodName;
+};
+
+struct DocumentRangeFormattingParams
+{
+ /**
+ * The document to format.
+ */
+ TextDocumentIdentifier textDocument;
+
+ /**
+ * The range to format
+ */
+ Range range;
+
+ /**
+ * The format options
+ */
+ //FormattingOptions options;
+
+ static const StructRttiInfo g_rttiInfo;
+ static const UnownedStringSlice methodName;
+};
+
+struct DocumentFormattingParams
+{
+ /**
+ * The document to format.
+ */
+ TextDocumentIdentifier textDocument;
+
+ /**
+ * The format options
+ */
+ //FormattingOptions options;
+
+ static const StructRttiInfo g_rttiInfo;
+ static const UnownedStringSlice methodName;
+};
+
} // namespace LanguageServerProtocol
} // namespace Slang
diff --git a/source/compiler-core/slang-lexer.cpp b/source/compiler-core/slang-lexer.cpp
index fd0255575..4a6d7d392 100644
--- a/source/compiler-core/slang-lexer.cpp
+++ b/source/compiler-core/slang-lexer.cpp
@@ -1340,9 +1340,12 @@ namespace Slang
}
}
- if (tokenType == TokenType::Identifier || tokenType == TokenType::CompletionRequest)
+ if (m_namePool)
{
- token.setName(m_namePool->getName(token.getContent()));
+ if (tokenType == TokenType::Identifier || tokenType == TokenType::CompletionRequest)
+ {
+ token.setName(m_namePool->getName(token.getContent()));
+ }
}
return token;