Use InImport pointing to C++ imports in ConvertLocInFile() instead of adding a separate InCppImport when emitting (#5614)

I believe we will need to eventually add the specific C++ import
information in `LocId`.

This also seems to fix the `LanguageServerDiagnosticInWrongFile` issue
(#5604).

We're still not in the state we want to be according to
https://github.com/carbon-language/carbon-lang/pull/5246#issuecomment-2784301206.
Will look into removing the location part from the `"In file included
from ..."` line.

Part of #5245.
This commit is contained in:
Boaz Brickner
2025-06-10 09:02:45 +00:00
committed by GitHub
parent 6683cf3b1c
commit ec97ec9664
9 changed files with 279 additions and 354 deletions
+9 -14
View File
@@ -19,20 +19,6 @@ constexpr Kind Kinds[] = {
#include "toolchain/diagnostics/diagnostic_kind.def"
};
// TODO: LanguageServerDiagnosticInWrongFile currently has coverage, but
// mainly due to incorrect behavior in C++ diagnostics. See
// language_server/testdata/text_document/open_with_cpp_nonexistent.carbon.
// Leaving this TODO here until it's more precisely tested, because the C++
// diagnostics should be fixed (removing coverage); see below TODO.
//
// TODO: This can only fire if the first message in a diagnostic is rooted
// in a file other than the file being compiled. The language server
// currently only supports compiling one file at a time. Do one of:
// - When imports are supported, find a diagnostic whose first message isn't
// in the current file.
// - Require all diagnostics produced by compiling have their first location
// be in the file being compiled, never an import.
// Kind::LanguageServerDiagnosticInWrongFile,
constexpr Kind UntestedKinds[] = {
// These exist only for unit tests.
Kind::TestDiagnostic,
@@ -56,6 +42,15 @@ constexpr Kind UntestedKinds[] = {
// This is a little long but is tested in lex/numeric_literal_test.cpp.
Kind::TooManyDigits,
// TODO: This can only fire if the first message in a diagnostic is rooted
// in a file other than the file being compiled. The language server
// currently only supports compiling one file at a time. Do one of:
// - When imports are supported, find a diagnostic whose first message isn't
// in the current file.
// - Require all diagnostics produced by compiling have their first location
// be in the file being compiled, never an import.
Kind::LanguageServerDiagnosticInWrongFile,
};
// Looks for diagnostic kinds that aren't covered by a file_test.