From 0c64995ea28febcc7d38e1519da8d93391ce2e7d Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 7 Jun 2022 14:10:49 -0700 Subject: Major language server features. (#2264) * Major language server features. * Include slangd in binary release. * Fix compiler issues. * Fix compiler error. * Completion resolve. * Various improvements. * Update diagnostic test expected output. * Bug fix for source locations. * Adjust diagnostic update frequency. * Update github actions to store artifacts. * Fix infinite parser loop. * Fix parser recovery. * Fix parser recovery. * Update test. * Fix test. * Disable IR gen for language server. * Allow commit characters in auto completion. * Fix lookup for invoke exprs. * More parser robustness fixes. * update solution file Co-authored-by: Yong He --- source/slang/slang.cpp | 60 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 13 deletions(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 9379f3b03..7602096d4 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -509,6 +509,8 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Session::createSession( targetDescPtr += targetDesc.structureSize; } + linkage->setFlags(desc.flags); + if(desc.flags & slang::kSessionFlag_FalcorCustomSharedKeywordSemantics) { linkage->m_useFalcorCustomSharedKeywordSemantics = true; @@ -529,6 +531,10 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Session::createSession( linkage->addPreprocessorDefine(macro.name, macro.value); } + if (desc.fileSystem) + { + linkage->setFileSystem(desc.fileSystem); + } *outSession = asExternal(linkage.detach()); return SLANG_OK; } @@ -926,6 +932,12 @@ SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModule( slang::IBlob** outDiagnostics) { DiagnosticSink sink(getSourceManager(), Lexer::sourceLocationLexer); + + if (m_flag & slang::kSessionFlag_LanguageServer) + { + sink.setFlags(DiagnosticSink::Flag::HumaneLoc | DiagnosticSink::Flag::LanguageServer); + } + try { auto name = getNamePool()->getName(moduleName); @@ -945,9 +957,16 @@ SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModule( SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModuleFromSource( const char* moduleName, + const char* path, slang::IBlob* source, slang::IBlob** outDiagnostics) { + DiagnosticSink sink(getSourceManager(), Lexer::sourceLocationLexer); + if (m_flag & slang::kSessionFlag_LanguageServer) + { + sink.setFlags(DiagnosticSink::Flag::HumaneLoc | DiagnosticSink::Flag::LanguageServer); + } + try { auto name = getNamePool()->getName(moduleName); @@ -956,10 +975,9 @@ SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModuleFromSource( { return loadedModule; } - DiagnosticSink sink(getSourceManager(), Lexer::sourceLocationLexer); auto module = loadModule( name, - PathInfo::makeFromString(moduleName), + PathInfo::makeFromString(path), source, SourceLoc(), &sink, @@ -970,6 +988,7 @@ SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModuleFromSource( } catch (const AbortCompilationException&) { + sink.getBlobIfNeeded(outDiagnostics); return nullptr; } } @@ -2567,17 +2586,29 @@ void Linkage::loadParsedModule( int errorCountBefore = sink->getErrorCount(); compileRequest->checkAllTranslationUnits(); int errorCountAfter = sink->getErrorCount(); - - if (errorCountAfter != errorCountBefore) + if (isInLanguageServer()) { - // There must have been an error in the loaded module. + // Don't generate IR as language server. + // This means that we currently cannot report errors that are detected during IR passes. + // Ideally we want to run those passes, but that is too risky for what it is worth right + // now. } else { - // If we didn't run into any errors, then try to generate - // IR code for the imported module. - SLANG_ASSERT(errorCountAfter == 0); - loadedModule->setIRModule(generateIRForTranslationUnit(getASTBuilder(), translationUnit)); + if (errorCountAfter != errorCountBefore) + { + // There must have been an error in the loaded module. + } + else + { + // If we didn't run into any errors, then try to generate + // IR code for the imported module. + if (errorCountAfter == 0) + { + loadedModule->setIRModule( + generateIRForTranslationUnit(getASTBuilder(), translationUnit)); + } + } } loadedModulesList.add(loadedModule); } @@ -2602,7 +2633,10 @@ void Linkage::_diagnoseErrorInImportedModule( { sink->diagnose(info->importLoc, Diagnostics::errorInImportedModule, info->name); } - sink->diagnose(SourceLoc(), Diagnostics::complationCeased); + if ((m_flag & slang::kSessionFlag_LanguageServer) == 0) + { + sink->diagnose(SourceLoc(), Diagnostics::complationCeased); + } } RefPtr Linkage::loadModule( @@ -2641,11 +2675,11 @@ RefPtr Linkage::loadModule( frontEndReq->parseTranslationUnit(translationUnit); int errorCountAfter = sink->getErrorCount(); - if( errorCountAfter != errorCountBefore ) + if (errorCountAfter != errorCountBefore && !isInLanguageServer()) { _diagnoseErrorInImportedModule(sink); } - if (errorCountAfter) + if (errorCountAfter && !isInLanguageServer()) { // Something went wrong during the parsing, so we should bail out. return nullptr; @@ -2659,7 +2693,7 @@ RefPtr Linkage::loadModule( errorCountAfter = sink->getErrorCount(); - if (errorCountAfter != errorCountBefore) + if (errorCountAfter != errorCountBefore && !isInLanguageServer()) { _diagnoseErrorInImportedModule(sink); // Something went wrong during the parsing, so we should bail out. -- cgit v1.2.3