Skip to content

Commit

Permalink
Fix language server for VS. (#3473)
Browse files Browse the repository at this point in the history
Co-authored-by: Yong He <yhe@nvidia.com>
  • Loading branch information
csyonghe and Yong He authored Jan 22, 2024
1 parent fdc17a9 commit c4e42ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions source/compiler-core/slang-json-rpc-connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ SlangResult JSONRPCConnection::sendError(JSONRPC::ErrorCode errorCode, const Uno
return sendRPC(&errorResponse);
}

SlangResult JSONRPCConnection::checkArrayObjectWrap( const JSONValue& srcArgs, const RttiInfo* dstArgsRttiInfo, void* dstArgs, const JSONValue& id )
{
if ( dstArgsRttiInfo->m_kind == RttiInfo::Kind::Struct &&
srcArgs.getKind() == JSONValue::Kind::Array )
{
auto array = m_container.getArray( srcArgs );
if ( array.getCount() == 1 )
{
return toNativeOrSendError( array[0], dstArgsRttiInfo, dstArgs, id );
}
return SLANG_OK;
}
else
{
return toNativeOrSendError( srcArgs, dstArgsRttiInfo, dstArgs, id );
}
}

SlangResult JSONRPCConnection::toNativeArgsOrSendError(const JSONValue& srcArgs, const RttiInfo* dstArgsRttiInfo, void* dstArgs, const JSONValue& id)
{
if (dstArgsRttiInfo->m_kind == RttiInfo::Kind::Struct &&
Expand Down
2 changes: 2 additions & 0 deletions source/compiler-core/slang-json-rpc-connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class JSONRPCConnection : public RefObject
/// Disconnect. May block while server shuts down
void disconnect();

SlangResult checkArrayObjectWrap( const JSONValue& srcArgs, const RttiInfo* dstArgsRttiInfo, void* dstArgs, const JSONValue& id );

/// Convert value to dst. Will write response on fails
SlangResult toNativeOrSendError(const JSONValue& value, const RttiInfo* info, void* dst, const JSONValue& id);

Expand Down
4 changes: 2 additions & 2 deletions source/slang/slang-language-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ SlangResult LanguageServer::queueJSONCall(JSONRPCCall call)
else if (call.method == SemanticTokensParams::methodName)
{
SemanticTokensParams args;
SLANG_RETURN_ON_FAIL(m_connection->toNativeArgsOrSendError(call.params, &args, call.id));
SLANG_RETURN_ON_FAIL(m_connection->checkArrayObjectWrap( call.params, GetRttiInfo<SemanticTokensParams>::get(), &args, call.id ));
cmd.semanticTokenArgs = args;
}
else if (call.method == SignatureHelpParams::methodName)
Expand All @@ -1995,7 +1995,7 @@ SlangResult LanguageServer::queueJSONCall(JSONRPCCall call)
else if (call.method == DocumentSymbolParams::methodName)
{
DocumentSymbolParams args;
SLANG_RETURN_ON_FAIL(m_connection->toNativeArgsOrSendError(call.params, &args, call.id));
SLANG_RETURN_ON_FAIL(m_connection->checkArrayObjectWrap( call.params, GetRttiInfo<DocumentSymbolParams>::get(), &args, call.id ));
cmd.documentSymbolArgs = args;
}
else if (call.method == DocumentFormattingParams::methodName)
Expand Down

0 comments on commit c4e42ab

Please sign in to comment.