Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (triSYCL#6)
Browse files Browse the repository at this point in the history
  CONFLICT (content): Merge conflict in clang/lib/Sema/Sema.cpp
  • Loading branch information
bader committed Apr 2, 2020
2 parents 253034f + 5767085 commit d9dbe81
Show file tree
Hide file tree
Showing 608 changed files with 9,811 additions and 4,768 deletions.
14 changes: 10 additions & 4 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
: nullptr),
GetClangTidyOptions(Opts.GetClangTidyOptions),
SuggestMissingIncludes(Opts.SuggestMissingIncludes),
TweakFilter(Opts.TweakFilter), WorkspaceRoot(Opts.WorkspaceRoot),
BuildRecoveryAST(Opts.BuildRecoveryAST), TweakFilter(Opts.TweakFilter),
WorkspaceRoot(Opts.WorkspaceRoot),
// Pass a callback into `WorkScheduler` to extract symbols from a newly
// parsed file and rebuild the file index synchronously each time an AST
// is parsed.
Expand Down Expand Up @@ -191,6 +192,7 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
Inputs.ForceRebuild = ForceRebuild;
Inputs.Opts = std::move(Opts);
Inputs.Index = Index;
Inputs.Opts.BuildRecoveryAST = BuildRecoveryAST;
bool NewFile = WorkScheduler.update(File, Inputs, WantDiags);
// If we loaded Foo.h, we want to make sure Foo.cpp is indexed.
if (NewFile && BackgroundIdx)
Expand Down Expand Up @@ -269,9 +271,13 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos,
if (!IP)
return CB(IP.takeError());

auto PreambleData = IP->Preamble;
CB(clangd::signatureHelp(File, IP->Command, PreambleData, IP->Contents, Pos,
FS, Index));
const auto *PreambleData = IP->Preamble;
if (!PreambleData)
return CB(llvm::createStringError(llvm::inconvertibleErrorCode(),
"Failed to parse includes"));

CB(clangd::signatureHelp(File, IP->Command, *PreambleData, IP->Contents,
Pos, FS, Index));
};

// Unlike code completion, we wait for an up-to-date preamble here.
Expand Down
6 changes: 6 additions & 0 deletions clang-tools-extra/clangd/ClangdServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ class ClangdServer {
/// enabled.
ClangTidyOptionsBuilder GetClangTidyOptions;

/// If true, turn on the `-frecovery-ast` clang flag.
bool BuildRecoveryAST = false;

/// Clangd's workspace root. Relevant for "workspace" operations not bound
/// to a particular file.
/// FIXME: If not set, should use the current working directory.
Expand Down Expand Up @@ -345,6 +348,9 @@ class ClangdServer {
// can be caused by missing includes (e.g. member access in incomplete type).
bool SuggestMissingIncludes = false;

// If true, preserve expressions in AST for broken code.
bool BuildRecoveryAST = false;

std::function<bool(const Tweak &)> TweakFilter;

// GUARDED_BY(CachedCompletionFuzzyFindRequestMutex)
Expand Down
21 changes: 11 additions & 10 deletions clang-tools-extra/clangd/CodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ class SignatureHelpCollector final : public CodeCompleteConsumer {
struct SemaCompleteInput {
PathRef FileName;
const tooling::CompileCommand &Command;
const PreambleData *Preamble;
const PreambleData &Preamble;
llvm::StringRef Contents;
size_t Offset;
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
Expand Down Expand Up @@ -1054,8 +1054,8 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
IncludeStructure *Includes = nullptr) {
trace::Span Tracer("Sema completion");
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = Input.VFS;
if (Input.Preamble && Input.Preamble->StatCache)
VFS = Input.Preamble->StatCache->getConsumingFS(std::move(VFS));
if (Input.Preamble.StatCache)
VFS = Input.Preamble.StatCache->getConsumingFS(std::move(VFS));
ParseInputs ParseInput;
ParseInput.CompileCommand = Input.Command;
ParseInput.FS = VFS;
Expand All @@ -1072,6 +1072,10 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
FrontendOpts.SkipFunctionBodies = true;
// Disable typo correction in Sema.
CI->getLangOpts()->SpellChecking = false;
// Code completion won't trigger in delayed template bodies.
// This is on-by-default in windows to allow parsing SDK headers; we're only
// disabling it for the main-file (not preamble).
CI->getLangOpts()->DelayedTemplateParsing = false;
// Setup code completion.
FrontendOpts.CodeCompleteOpts = Options;
FrontendOpts.CodeCompletionAt.FileName = std::string(Input.FileName);
Expand All @@ -1095,9 +1099,7 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
// NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise
// the remapped buffers do not get freed.
auto Clang = prepareCompilerInstance(
std::move(CI),
(Input.Preamble && !CompletingInPreamble) ? &Input.Preamble->Preamble
: nullptr,
std::move(CI), !CompletingInPreamble ? &Input.Preamble.Preamble : nullptr,
std::move(ContentsBuffer), std::move(VFS), IgnoreDiags);
Clang->getPreprocessorOpts().SingleFileParseMode = CompletingInPreamble;
Clang->setCodeCompletionConsumer(Consumer.release());
Expand All @@ -1114,8 +1116,7 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
// - but Sema code complete won't see them: as part of the preamble, they're
// deserialized only when mentioned.
// Force them to be deserialized so SemaCodeComplete sees them.
if (Input.Preamble)
loadMainFilePreambleMacros(Clang->getPreprocessor(), *Input.Preamble);
loadMainFilePreambleMacros(Clang->getPreprocessor(), Input.Preamble);
if (Includes)
Clang->getPreprocessor().addPPCallbacks(
collectIncludeStructureCallback(Clang->getSourceManager(), Includes));
Expand Down Expand Up @@ -1754,12 +1755,12 @@ codeComplete(PathRef FileName, const tooling::CompileCommand &Command,
return (!Preamble || Opts.RunParser == CodeCompleteOptions::NeverParse)
? std::move(Flow).runWithoutSema(Contents, *Offset, VFS)
: std::move(Flow).run(
{FileName, Command, Preamble, Contents, *Offset, VFS});
{FileName, Command, *Preamble, Contents, *Offset, VFS});
}

SignatureHelp signatureHelp(PathRef FileName,
const tooling::CompileCommand &Command,
const PreambleData *Preamble,
const PreambleData &Preamble,
llvm::StringRef Contents, Position Pos,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
const SymbolIndex *Index) {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/CodeComplete.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ CodeCompleteResult codeComplete(PathRef FileName,
/// Get signature help at a specified \p Pos in \p FileName.
SignatureHelp signatureHelp(PathRef FileName,
const tooling::CompileCommand &Command,
const PreambleData *Preamble, StringRef Contents,
const PreambleData &Preamble, StringRef Contents,
Position Pos,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
const SymbolIndex *Index);
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class IgnoreDiagnostics : public DiagnosticConsumer {
struct ParseOptions {
tidy::ClangTidyOptions ClangTidyOpts;
bool SuggestMissingIncludes = false;
bool BuildRecoveryAST = false;
};

/// Information required to run clang, e.g. to parse AST or do code completion.
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/clangd/ParsedAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ ParsedAST::build(llvm::StringRef Version,
const PrecompiledPreamble *PreamblePCH =
Preamble ? &Preamble->Preamble : nullptr;

// Recovery expression currently only works for C++.
if (CI->getLangOpts()->CPlusPlus)
CI->getLangOpts()->RecoveryAST = Opts.BuildRecoveryAST;

StoreDiags ASTDiags;
std::string Content = std::string(Buffer->getBuffer());
std::string Filename =
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/clangd/Preamble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ buildPreamble(PathRef FileName, CompilerInvocation &CI,
// to read back. We rely on dynamic index for the comments instead.
CI.getPreprocessorOpts().WriteCommentListToPCH = false;

// Recovery expression currently only works for C++.
if (CI.getLangOpts()->CPlusPlus)
CI.getLangOpts()->RecoveryAST = Inputs.Opts.BuildRecoveryAST;

CppFilePreambleCallbacks SerializedDeclsCollector(FileName, PreambleCallback);
if (Inputs.FS->setCurrentWorkingDirectory(Inputs.CompileCommand.Directory)) {
log("Couldn't set working directory when building the preamble.");
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/SemanticHighlighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ llvm::StringRef toSemanticTokenType(HighlightingKind Kind) {
case HighlightingKind::InactiveCode:
return "comment";
}
llvm_unreachable("unhandled HighlightingKind");
}

std::vector<TheiaSemanticHighlightingInformation>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// A launch configuration that compiles extension and opens it inside a new window.
{
"version": "0.1.0",
"configurations": [
Expand Down
24 changes: 13 additions & 11 deletions clang-tools-extra/clangd/clients/clangd-vscode/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process

// A task runner that calls a custom npm script that compiles the extension.
// Task runner calls custom npm script to compile the extension.
{
"version": "0.1.0",
"version": "2.0.0",

// we want to run npm
// Run NPM.
"command": "npm",

// the command is a shell script
"isShellCommand": true,
// This command is a shell script.
"type": "shell",

// show the output window only if unrecognized errors occur.
"showOutput": "silent",
"presentation": {
"reveal": "silent",
},

// we run the custom script "compile" as defined in package.json
// Run custom "compile" script as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],

// The tsc compiler is started in watching mode
"isWatching": true,
// tsc compiler is kept alive and runs in the background.
"isBackground": true,

// use the standard tsc in watch mode problem matcher to find compile problems in the output.
// Find compilation problems in the output through tsc in watch mode.
"problemMatcher": "$tsc-watch"
}
}
16 changes: 8 additions & 8 deletions clang-tools-extra/clangd/clients/clangd-vscode/DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ A guide of developing `vscode-clangd` extension.
## Steps

1. Make sure you disable the installed `vscode-clangd` extension in VS Code.
2. Make sure you have clangd in /usr/bin/clangd or edit src/extension.ts to
2. Make sure you have clangd in `/usr/bin/clangd` or edit `src/extension.ts` to
point to the binary.
3. In order to start a development instance of VS code extended with this, run:
3. To start a development instance of VS code extended with this, run:

```bash
$ cd /path/to/clang-tools-extra/clangd/clients/clangd-vscode/
$ npm install
$ code .
# When VS Code starts, press <F5>.
# When VSCode starts, press <F5>.
```

# Contributing

Please follow the exsiting code style when contributing to the extension, we
Please follow the existing code style when contributing to the extension, we
recommend to run `npm run format` before sending a patch.

# Publish to VS Code Marketplace
Expand All @@ -38,15 +38,15 @@ to the marketplace.
* Bump the version in `package.json`, and commit the change to upstream

The extension is published under `llvm-vs-code-extensions` account, which is
currently maintained by clangd developers. If you want to make a new release,
please contact clangd-dev@lists.llvm.org.
maintained by clangd developers. If you want to make a new release, please
contact clangd-dev@lists.llvm.org.

## Steps

```bash
$ cd /path/to/clang-tools-extra/clangd/clients/clangd-vscode/
# For the first time, you need to login in the account. vsce will ask you for
the Personal Access Token, and remember it for future commands.
# For the first time, you need to login into the account. vsce will ask you
for the Personal Access Token and will remember it for future commands.
$ vsce login llvm-vs-code-extensions
# Publish the extension to the VSCode marketplace.
$ npm run publish
Expand Down
12 changes: 6 additions & 6 deletions clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as vscodelc from 'vscode-languageclient';
import * as semanticHighlighting from './semantic-highlighting';

/**
* Method to get workspace configuration option
* Get an option from workspace configuration.
* @param option name of the option (e.g. for clangd.path should be path)
* @param defaultValue default value to return if option is not set
*/
Expand Down Expand Up @@ -75,8 +75,8 @@ class EnableEditsNearCursorFeature implements vscodelc.StaticFeature {
}

/**
* this method is called when your extension is activate
* your extension is activated the very first time the command is executed
* This method is called when the extension is activated. The extension is
* activated the very first time a command is executed.
*/
export function activate(context: vscode.ExtensionContext) {
const syncFileEvents = getConfig<boolean>('syncFileEvents', true);
Expand All @@ -97,7 +97,7 @@ export function activate(context: vscode.ExtensionContext) {
documentSelector: [
{ scheme: 'file', language: 'c' },
{ scheme: 'file', language: 'cpp' },
// cuda is not supported by vscode, but our extension does.
// CUDA is not supported by vscode, but our extension does supports it.
{ scheme: 'file', language: 'cuda' },
{ scheme: 'file', language: 'objective-c'},
{ scheme: 'file', language: 'objective-cpp'}
Expand All @@ -106,7 +106,7 @@ export function activate(context: vscode.ExtensionContext) {
// FIXME: send sync file events when clangd provides implementations.
},
initializationOptions: { clangdFileStatus: true },
// Do not switch to output window when clangd returns output
// Do not switch to output window when clangd returns output.
revealOutputChannelOn: vscodelc.RevealOutputChannelOn.Never,

// We hack up the completion items a bit to prevent VSCode from re-ranking them
Expand All @@ -126,7 +126,7 @@ export function activate(context: vscode.ExtensionContext) {
provideCompletionItem: async (document, position, context, token, next) => {
let list = await next(document, position, context, token);
let items = (Array.isArray(list) ? list : list.items).map(item => {
// Gets the prefix used by vscode when doing fuzzymatch.
// Gets the prefix used by VSCode when doing fuzzymatch.
let prefix = document.getText(new vscode.Range(item.range.start, position))
if (prefix)
item.filterText = prefix + "_" + item.filterText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
"node_modules",
".vscode-test"
]
}
}
10 changes: 10 additions & 0 deletions clang-tools-extra/clangd/tool/ClangdMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ opt<bool> CrossFileRename{
Hidden,
};

opt<bool> RecoveryAST{
"recovery-ast",
cat(Features),
desc("Preserve expressions in AST for broken code (C++ only). Note that "
"this feature is experimental and may lead to crashes"),
init(false),
Hidden,
};

opt<unsigned> WorkerThreadsCount{
"j",
cat(Misc),
Expand Down Expand Up @@ -629,6 +638,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
}
Opts.StaticIndex = StaticIdx.get();
Opts.AsyncThreadsCount = WorkerThreadsCount;
Opts.BuildRecoveryAST = RecoveryAST;

clangd::CodeCompleteOptions CCOpts;
CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
Expand Down
4 changes: 1 addition & 3 deletions clang-tools-extra/clangd/unittests/ClangdTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,15 +552,13 @@ TEST_F(ClangdVFSTest, InvalidCompileCommand) {
EXPECT_ERROR(runFindDocumentHighlights(Server, FooCpp, Position()));
EXPECT_ERROR(runRename(Server, FooCpp, Position(), "new_name",
clangd::RenameOptions()));
EXPECT_ERROR(runSignatureHelp(Server, FooCpp, Position()));
// Identifier-based fallback completion.
EXPECT_THAT(cantFail(runCodeComplete(Server, FooCpp, Position(),
clangd::CodeCompleteOptions()))
.Completions,
ElementsAre(Field(&CodeCompletion::Name, "int"),
Field(&CodeCompletion::Name, "main")));
auto SigHelp = runSignatureHelp(Server, FooCpp, Position());
ASSERT_TRUE(bool(SigHelp)) << "signatureHelp returned an error";
EXPECT_THAT(SigHelp->signatures, IsEmpty());
}

class ClangdThreadingTest : public ClangdVFSTest {};
Expand Down
Loading

0 comments on commit d9dbe81

Please sign in to comment.