Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.

"LSP Snippets" option for completion API #1296

Open
wants to merge 2 commits into
base: tensorflow
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/lldb/API/LLDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "lldb/API/SBStructuredData.h"
// SWIFT_ENABLE_TENSORFLOW
#include "lldb/API/SBCompletionMatch.h"
#include "lldb/API/SBCompletionOptions.h"
#include "lldb/API/SBCompletionResponse.h"
#include "lldb/API/SBSymbol.h"
#include "lldb/API/SBSymbolContext.h"
Expand Down
48 changes: 48 additions & 0 deletions include/lldb/API/SBCompletionOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//===-- SBCompletionOptions.h -----------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_SBCompletionOptions_h_
#define LLDB_SBCompletionOptions_h_

#include "lldb/API/SBDefines.h"
#include "lldb/Target/CompletionOptions.h"

namespace lldb {

class LLDB_API SBCompletionOptions {
public:
SBCompletionOptions();

SBCompletionOptions(const SBCompletionOptions &rhs);

const SBCompletionOptions &operator=(const SBCompletionOptions &rhs);

lldb::LanguageType GetLanguage() const;
void SetLanguage(lldb::LanguageType Language);

bool GetInsertableLSPSnippets() const;
void SetInsertableLSPSnippets(bool Value);

protected:
friend class SBTarget;

SBCompletionOptions(const lldb_private::CompletionOptions *options);

lldb_private::CompletionOptions *GetPointer() const;

private:
std::unique_ptr<lldb_private::CompletionOptions> m_opaque_ap;
};

} // namespace lldb

#endif // LLDB_SBCompletionOptions_h_
2 changes: 2 additions & 0 deletions include/lldb/API/SBDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class LLDB_API SBCommandPluginInterface;
class LLDB_API SBCommandReturnObject;
class LLDB_API SBCommunication;
class LLDB_API SBCompileUnit;
// SWIFT_ENABLE_TENSORFLOW
class LLDB_API SBCompletionMatch;
class LLDB_API SBCompletionOptions;
class LLDB_API SBCompletionResponse;
class LLDB_API SBData;
class LLDB_API SBDebugger;
Expand Down
2 changes: 1 addition & 1 deletion include/lldb/API/SBTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ class LLDB_API SBTarget {

// SWIFT_ENABLE_TENSORFLOW
SBCompletionResponse
CompleteCode(lldb::LanguageType language,
CompleteCode(const lldb::SBCompletionOptions &options,
const lldb::SBSymbolContext *symbol_context,
const char *current_code);

Expand Down
25 changes: 25 additions & 0 deletions include/lldb/Target/CompletionOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===--- CompletionOptions.h ------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef CompletionOptions_h_
#define CompletionOptions_h_

namespace lldb_private {

struct CompletionOptions {
lldb::LanguageType Language;
bool InsertableLSPSnippets = false;
};

} // namespace lldb_private

#endif // CompletionOptions_h_
4 changes: 3 additions & 1 deletion include/lldb/Target/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "lldb/DataFormatters/StringPrinter.h"
// SWIFT_ENABLE_TENSORFLOW
#include "lldb/Target/CompletionResponse.h"
#include "lldb/Target/CompletionOptions.h"
#include "lldb/lldb-private.h"
#include "lldb/lldb-public.h"

Expand Down Expand Up @@ -234,7 +235,8 @@ class Language : public PluginInterface {
bool throw_on, Stream &s);

// SWIFT_ENABLE_TENSORFLOW
virtual CompletionResponse CompleteCode(ExecutionContextScope &exe_scope,
virtual CompletionResponse CompleteCode(const CompletionOptions &options,
ExecutionContextScope &exe_scope,
const std::string &entered_code);

// These are accessors for general information about the Languages lldb knows
Expand Down
6 changes: 4 additions & 2 deletions include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Target/ABI.h"
// SWIFT_ENABLE_TENSORFLOW
#include "lldb/Target/CompletionOptions.h"
#include "lldb/Target/CompletionResponse.h"
#include "lldb/Target/ExecutionContextScope.h"
#include "lldb/Target/PathMappingList.h"
Expand Down Expand Up @@ -1220,8 +1221,9 @@ class Target : public std::enable_shared_from_this<Target>,
std::string *fixed_expression = nullptr);

// SWIFT_ENABLE_TENSORFLOW
CompletionResponse CompleteCode(lldb::LanguageType language,
llvm::StringRef current_code);
CompletionResponse CompleteCode(
const lldb_private::CompletionOptions &options,
llvm::StringRef current_code);

// Look up a symbol by name and type in both the target's symbols and the
// persistent symbols from the
Expand Down
45 changes: 45 additions & 0 deletions scripts/interface/SBCompletionOptions.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//===-- SWIG Interface for SBCompletionOptions ------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

namespace lldb {

%feature("docstring", "
Options for a completion request
") SBCompletionOptions;
class SBCompletionOptions
{
public:
%feature("docstring", "The language used for completions.")
GetLanguage;
lldb::LanguageType GetLanguage () const;

%feature("docstring", "Set the language used for completions.")
SetLanguage;
void SetLanguage (lldb::LanguageType Language);

%feature("docstring", "
When this is false, the insertable text in completion matches is plain text
that can be inserted directly into the code. When this is true, the
insertable text in completion matches is a Language Server Protocol Snippet
(https://microsoft.github.io/language-server-protocol/specification#textDocument_completion),
which includes things like placeholder tabstops for function arguments.
") GetInsertableLSPSnippets;
bool GetInsertableLSPSnippets () const;

%feature("docstring", "
Set whether the insertable text in completion matches is a Language Server
Protocol Snippet. See the getter docstring for more information.
") SetInsertableLSPSnippets;
void SetInsertableLSPSnippets (bool Value);
};

} // namespace lldb
4 changes: 2 additions & 2 deletions scripts/interface/SBTarget.i
Original file line number Diff line number Diff line change
Expand Up @@ -1039,14 +1039,14 @@ public:
%feature("docstring", "
Complete code.
Parameters:
language -- the language to use
options -- the options to use
symbol_context -- the context in which to do the completion
current_code -- the code to complete
Returns an SBCompletionResponse with completions that fit immediately after
the last character of `current_code`.
") CompleteCode;
lldb::SBCompletionResponse
CompleteCode (lldb::LanguageType language,
CompleteCode (const lldb::SBCompletionOptions &options,
const lldb::SBSymbolContext *symbol_context,
const char *current_code);

Expand Down
2 changes: 2 additions & 0 deletions scripts/lldb.swig
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import six
#include "lldb/API/SBCompileUnit.h"
// SWIFT_ENABLE_TENSORFLOW
#include "lldb/API/SBCompletionMatch.h"
#include "lldb/API/SBCompletionOptions.h"
#include "lldb/API/SBCompletionResponse.h"
#include "lldb/API/SBData.h"
#include "lldb/API/SBDebugger.h"
Expand Down Expand Up @@ -180,6 +181,7 @@ import six
%include "./interface/SBCompileUnit.i"
// SWIFT_ENABLE_TENSORFLOW
%include "./interface/SBCompletionMatch.i"
%include "./interface/SBCompletionOptions.i"
%include "./interface/SBCompletionResponse.i"
%include "./interface/SBData.i"
%include "./interface/SBDebugger.i"
Expand Down
1 change: 1 addition & 0 deletions source/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_lldb_library(liblldb SHARED
SBCommunication.cpp
SBCompileUnit.cpp
SBCompletionMatch.cpp
SBCompletionOptions.cpp
SBCompletionResponse.cpp
SBData.cpp
SBDebugger.cpp
Expand Down
53 changes: 53 additions & 0 deletions source/API/SBCompletionOptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===-- SBCompletionOptions.cpp ---------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "lldb/API/SBCompletionOptions.h"

using namespace lldb;
using namespace lldb_private;

SBCompletionOptions::SBCompletionOptions()
: m_opaque_ap(new lldb_private::CompletionOptions()) {}

SBCompletionOptions::SBCompletionOptions(const SBCompletionOptions &rhs)
: m_opaque_ap(new lldb_private::CompletionOptions(*rhs.m_opaque_ap)) {}

const SBCompletionOptions &SBCompletionOptions::
operator=(const SBCompletionOptions &rhs) {
m_opaque_ap.reset(new lldb_private::CompletionOptions(*rhs.m_opaque_ap));
return *this;
}

lldb::LanguageType SBCompletionOptions::GetLanguage() const {
return m_opaque_ap->Language;
}

void SBCompletionOptions::SetLanguage(lldb::LanguageType Language) {
m_opaque_ap->Language = Language;
}

bool SBCompletionOptions::GetInsertableLSPSnippets() const {
return m_opaque_ap->InsertableLSPSnippets;
}

void SBCompletionOptions::SetInsertableLSPSnippets(bool Value) {
m_opaque_ap->InsertableLSPSnippets = Value;
}

SBCompletionOptions::SBCompletionOptions(
const lldb_private::CompletionOptions *options)
: m_opaque_ap(new lldb_private::CompletionOptions(*options)) {}


lldb_private::CompletionOptions *SBCompletionOptions::GetPointer() const {
return m_opaque_ap.get();
}
5 changes: 3 additions & 2 deletions source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "lldb/API/SBBreakpoint.h"
#include "lldb/API/SBDebugger.h"
// SWIFT_ENABLE_TENSORFLOW
#include "lldb/API/SBCompletionOptions.h"
#include "lldb/API/SBCompletionResponse.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBExpressionOptions.h"
Expand Down Expand Up @@ -2308,10 +2309,10 @@ lldb::SBValue SBTarget::EvaluateExpression(const char *expr,

// SWIFT_ENABLE_TENSORFLOW
SBCompletionResponse
SBTarget::CompleteCode(lldb::LanguageType language,
SBTarget::CompleteCode(const lldb::SBCompletionOptions &options,
const lldb::SBSymbolContext *symbol_context,
const char *current_code) {
auto response = GetSP()->CompleteCode(language, current_code);
auto response = GetSP()->CompleteCode(*options.GetPointer(), current_code);
return SBCompletionResponse(&response);
}

Expand Down
Loading