summaryrefslogtreecommitdiffstats
path: root/source/compiler-core
diff options
context:
space:
mode:
Diffstat (limited to 'source/compiler-core')
-rw-r--r--source/compiler-core/slang-diagnostic-sink.cpp52
-rw-r--r--source/compiler-core/slang-diagnostic-sink.h3
-rw-r--r--source/compiler-core/slang-doc-extractor.cpp3
-rw-r--r--source/compiler-core/slang-json-native.cpp4
-rw-r--r--source/compiler-core/slang-json-rpc-connection.cpp2
-rw-r--r--source/compiler-core/slang-json-rpc-connection.h2
-rw-r--r--source/compiler-core/slang-json-rpc.cpp1
-rw-r--r--source/compiler-core/slang-source-loc.cpp2
8 files changed, 64 insertions, 5 deletions
diff --git a/source/compiler-core/slang-diagnostic-sink.cpp b/source/compiler-core/slang-diagnostic-sink.cpp
index 314ec1c2c..0110b16d7 100644
--- a/source/compiler-core/slang-diagnostic-sink.cpp
+++ b/source/compiler-core/slang-diagnostic-sink.cpp
@@ -138,6 +138,10 @@ static void formatDiagnostic(const HumaneSourceLoc& humaneLoc, Diagnostic const&
outBuilder << humaneLoc.pathInfo.foundPath;
outBuilder << "(";
outBuilder << Int32(humaneLoc.line);
+ if (flags & DiagnosticSink::Flag::LanguageServer)
+ {
+ outBuilder << ", " << humaneLoc.column;
+ }
outBuilder << "): ";
}
@@ -348,6 +352,47 @@ static void _sourceLocationNoteDiagnostic(DiagnosticSink* sink, SourceView* sour
sb << caretLine << "\n";
}
+// Output the length of the token at `sourceLoc`. This is used by language server.
+static void _tokenLengthNoteDiagnostic(
+ DiagnosticSink* sink, SourceView* sourceView, SourceLoc sourceLoc, StringBuilder& sb)
+{
+ SourceFile* sourceFile = sourceView->getSourceFile();
+ if (!sourceFile)
+ {
+ return;
+ }
+
+ UnownedStringSlice content = sourceFile->getContent();
+
+ // Make sure the offset is within content.
+ // This is important because it's possible to have a 'SourceFile' that doesn't contain any
+ // content (for example when reconstructed via serialization with just line offsets, the actual
+ // source text 'content' isn't available).
+ const int offset = sourceView->getRange().getOffset(sourceLoc);
+ if (offset < 0 || offset >= content.getLength())
+ {
+ return;
+ }
+
+ // Work out the position of the SourceLoc in the source
+ const char* const pos = content.begin() + offset;
+
+ UnownedStringSlice line = _extractLineContainingPosition(content, pos);
+
+ // Trim any trailing white space
+ line = UnownedStringSlice(line.begin(), line.trim().end());
+
+ auto lexer = sink->getSourceLocationLexer();
+ if (lexer)
+ {
+ UnownedStringSlice token = lexer(UnownedStringSlice(pos, line.end()));
+
+ if (token.getLength() > 1)
+ {
+ sb << "^+" << token.getLength() << "\n";
+ }
+ }
+}
static void formatDiagnostic(
DiagnosticSink* sink,
@@ -365,6 +410,7 @@ static void formatDiagnostic(
{
humaneLoc = sourceView->getHumaneLoc(sourceLoc);
}
+
formatDiagnostic(humaneLoc, diagnostic, sink->getFlags(), sb);
{
@@ -404,6 +450,12 @@ static void formatDiagnostic(
}
}
+ // If we are a language server, output additional token length info.
+ if (sourceView && sink->isFlagSet(DiagnosticSink::Flag::LanguageServer))
+ {
+ _tokenLengthNoteDiagnostic(sink, sourceView, sourceLoc, sb);
+ }
+
// We don't don't output source line information if this is a 'note' as a note is extra information for one
// of the other main severity types, and so the information should already be output on the initial line
if (sourceView && sink->isFlagSet(DiagnosticSink::Flag::SourceLocationLine) && diagnostic.severity != Severity::Note)
diff --git a/source/compiler-core/slang-diagnostic-sink.h b/source/compiler-core/slang-diagnostic-sink.h
index b78023bc8..c4d2e07d3 100644
--- a/source/compiler-core/slang-diagnostic-sink.h
+++ b/source/compiler-core/slang-diagnostic-sink.h
@@ -150,7 +150,8 @@ public:
VerbosePath = 0x1, ///< Will display a more verbose path (if available) - such as a canonical or absolute path
SourceLocationLine = 0x2, ///< If set will display the location line if source is available
HumaneLoc = 0x4, ///< If set will display humane locs (filename/line number) information
- TreatWarningsAsErrors = 0x8 ///< If set will turn all Warning type messages (after overrides) into Error type messages
+ TreatWarningsAsErrors = 0x8, ///< If set will turn all Warning type messages (after overrides) into Error type messages
+ LanguageServer = 0x10, ///< If set will format message in a way that is suitable for language server
};
};
diff --git a/source/compiler-core/slang-doc-extractor.cpp b/source/compiler-core/slang-doc-extractor.cpp
index c2200cf37..363108548 100644
--- a/source/compiler-core/slang-doc-extractor.cpp
+++ b/source/compiler-core/slang-doc-extractor.cpp
@@ -731,7 +731,8 @@ SlangResult DocMarkupExtractor::extract(const SearchItemInput* inputs, Index inp
{
// Find the new view
sourceView = sourceManager->findSourceView(loc);
- SLANG_ASSERT(sourceView);
+ if (!sourceView)
+ return SLANG_FAIL;
// We want only one view per SourceFile
SourceFile* sourceFile = sourceView->getSourceFile();
diff --git a/source/compiler-core/slang-json-native.cpp b/source/compiler-core/slang-json-native.cpp
index 6e54457d0..d268fffc2 100644
--- a/source/compiler-core/slang-json-native.cpp
+++ b/source/compiler-core/slang-json-native.cpp
@@ -136,7 +136,7 @@ SlangResult JSONToNativeConverter::convert(const JSONValue& in, const RttiInfo*
Index fieldCount = 0;
SLANG_RETURN_ON_FAIL(_structToNative(pairs, structRttiInfo, out, fieldCount));
- if (fieldCount != pairs.getCount())
+ if (fieldCount != pairs.getCount() && !structRttiInfo->m_ignoreUnknownFieldsInJson)
{
// We want to find the fields not found in the type
@@ -176,6 +176,8 @@ SlangResult JSONToNativeConverter::convert(const JSONValue& in, const RttiInfo*
}
case RttiInfo::Kind::List:
{
+ if (in.getKind() == JSONValue::Kind::Null)
+ return SLANG_OK;
if (in.getKind() != JSONValue::Kind::Array)
{
return SLANG_FAIL;
diff --git a/source/compiler-core/slang-json-rpc-connection.cpp b/source/compiler-core/slang-json-rpc-connection.cpp
index cad2f8e19..ec45f5b82 100644
--- a/source/compiler-core/slang-json-rpc-connection.cpp
+++ b/source/compiler-core/slang-json-rpc-connection.cpp
@@ -157,7 +157,7 @@ SlangResult JSONRPCConnection::toNativeOrSendError(const JSONValue& value, const
}
return SLANG_OK;
-}
+}
SlangResult JSONRPCConnection::sendCall(const UnownedStringSlice& method, const JSONValue& id)
{
diff --git a/source/compiler-core/slang-json-rpc-connection.h b/source/compiler-core/slang-json-rpc-connection.h
index 1436e9601..07b7cc347 100644
--- a/source/compiler-core/slang-json-rpc-connection.h
+++ b/source/compiler-core/slang-json-rpc-connection.h
@@ -50,6 +50,7 @@ public:
/// Convert value to dst. Will write response on fails
SlangResult toNativeOrSendError(const JSONValue& value, const RttiInfo* info, void* dst, const JSONValue& id);
+
template <typename T>
SlangResult toNativeOrSendError(const JSONValue& value, T* data, const JSONValue& id) { return toNativeOrSendError(value, GetRttiInfo<T>::get(), data, id); }
@@ -59,6 +60,7 @@ public:
/// toNativeOrSendError does not assume the thing being converted is args, and so doesn't allow such a transformation.
/// Will write error response on failure.
SlangResult toNativeArgsOrSendError(const JSONValue& srcArgs, const RttiInfo* dstArgsRttiInfo, void* dstArgs, const JSONValue& id);
+
template <typename T>
SlangResult toNativeArgsOrSendError(const JSONValue& srcArgs, T* dstArgs, const JSONValue& id) { return toNativeArgsOrSendError(srcArgs, GetRttiInfo<T>::get(), dstArgs, id); }
diff --git a/source/compiler-core/slang-json-rpc.cpp b/source/compiler-core/slang-json-rpc.cpp
index 660bbd4b7..f4101be8c 100644
--- a/source/compiler-core/slang-json-rpc.cpp
+++ b/source/compiler-core/slang-json-rpc.cpp
@@ -54,6 +54,7 @@ static const StructRttiInfo _makeJSONRPCCallResponseRtti()
builder.addField("method", &obj.method);
builder.addField("params", &obj.params, StructRttiInfo::Flag::Optional);
builder.addField("id", &obj.id, StructRttiInfo::Flag::Optional);
+ builder.ignoreUnknownFields();
return builder.make();
}
diff --git a/source/compiler-core/slang-source-loc.cpp b/source/compiler-core/slang-source-loc.cpp
index 3033d9626..f245d1e0c 100644
--- a/source/compiler-core/slang-source-loc.cpp
+++ b/source/compiler-core/slang-source-loc.cpp
@@ -176,7 +176,7 @@ HumaneSourceLoc SourceView::getHumaneLoc(SourceLoc loc, SourceLocType type)
// We need the line index from the original source file
const int lineIndex = m_sourceFile->calcLineIndexFromOffset(offset);
-
+
// TODO: we should really translate the byte index in the line
// to deal with:
//