IntelliSense 멤버가 완료 (패키지 관리 프레임 워크)
IntelliSense 멤버가 완료 가능한 멤버가 클래스, 구조체, 열거형 또는 네임 스페이스와 같은 특정 범위의 목록을 표시 하는 도구 설명이 있습니다. "This"는 마침표 다음에 사용자가 입력 하는 경우 예를 들어, C# 클래스 또는 구조체의 현재 범위에 대 한 모든 멤버의 목록은 사용자가 선택할 수 있는 목록에 표시 됩니다.
패키지 관리 프레임 워크 (MPF) 도구 설명 및 도구 설명에는 목록 관리에 대 한 지원. 필요 하며 협력에서 목록에 표시 되는 데이터를 제공 하는 파서가 있습니다.
작동 방식
MPF 클래스를 사용 하 여 멤버 목록 표시 되는 두 가지 방법을 다음과 같습니다.
식별자 또는 멤버가 완료 문자 다음에 오는 캐럿 위치를 지정 하 고 선택 목록 구성원 에서 IntelliSense 메뉴.
IScanner 스캐너 멤버가 완료 문자를 검색 하 고 토큰 트리거를 설정 하는 MemberSelect 해당 문자에 대해.
구성원 완성 문자 클래스, 구조체, 열거형의 멤버를 수행입니다. 예를 들어, C# 또는 Visual Basic 멤버 완성 문자입니다는 ., c + +에서 문자 하나 되는 동안에 . 또는 ->. 구성원 선택 문자를 검색할 때 트리거 값이 설정 됩니다.
IntelliSense 멤버 목록 명령
SHOWMEMBERLIST 명령에 대 한 호출을 시작는 Completion 메서드를는 Source 클래스 및 Completion 메서드를 차례로 호출 하는 ParseSource 메서드 파서가 구문 분석 이유의 DisplayMemberList.
파서가 현재 위치 처럼 하거나 현재 위치 바로 앞의 토큰의 컨텍스트를 결정합니다. 이 토큰을 기반으로 선언 목록이 표시 됩니다. 예를 들어,에서 C# 클래스 멤버 및 선택에 캐럿 배치 하는 경우, 멤버 목록, 클래스의 모든 멤버의 목록을 가져옵니다. 개체 변수 뒤에 오는 기간 후 캐럿을 배치할 경우 목록을 나타내는 개체 클래스의 모든 멤버를 가져옵니다. Note 멤버 목록이 표시 될 때 구성원에 캐럿 배치 되 면 목록에서 구성원을 선택 하면 멤버 목록에서 1 캐럿입니다 대체 됩니다.
토큰 시작 옵션
MemberSelect 트리거 초기화를 호출 하는 Completion 메서드를는 Source 클래스 및 Completion 메서드를 차례로 호출 파서가 구문 분석 이유의 MemberSelect (토큰 트리거가 포함 되어 있는 경우는 MatchBraces 플래그를 구문 분석 하는 이유입니다 MemberSelectAndHighlightBraces 멤버 선택 및 중괄호 강조 결합).
현재 컨텍스트 파서가 결정 문자 멤버를 선택 하기 전에 어떤 입력 한 같은 위치입니다. 이 정보에서 파서는 요청 된 범위에 모든 멤버의 목록을 만듭니다. 이 선언은 목록에 저장 됩니다는 AuthoringScope 에서 반환 되는 개체는 ParseSource 메서드. 모든 선언 반환 되는 경우 멤버가 완료 도구 설명이 표시 됩니다. 도구 설명의 인스턴스에서 관리 되는 CompletionSet 클래스입니다.
멤버가 완료에 대 한 지원 사용
있어야 합니다의 CodeSense IntelliSense 작업을 지원 하도록 레지스트리 항목이 1로 설정 합니다. 명명 된 매개 변수가 전달 된이 레지스트리 항목을 설정할 수 있습니다에서 ProvideLanguageServiceAttribute 언어 패키지와 연관 된 사용자 정의 특성입니다. 언어 서비스 클래스에서이 레지스트리 항목의 값을 읽기는 EnableCodeSense 속성에는 LanguagePreferences 클래스입니다.
스캐너가 토큰 트리거를 반환 하는 경우 MemberSelect, 파서를 선언, 목록을 반환 하 고 멤버 완성 목록이 표시 됩니다.
스캐너에서 지 원하는 멤버 완성
스캐너 멤버가 완료 문자를 검색 하 고 토큰 트리거를 설정할 수 있어야 합니다. MemberSelect 때 문자 구문 분석 됩니다.
예제
멤버가 완료 문자를 검색 하 고 적절 한 설정의 단순화 된 예 TokenTriggers 플래그입니다. 이 예제는 설명을 위한 것입니다. 스캐너는 메서드를 포함 하는 가정 GetNextToken 를 식별 하 고 텍스트 줄의 토큰을 반환 합니다. 간단 하 게 예제 코드의 문자 종류를 볼 때마다 트리거를 설정 합니다.
using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.TextManager.Interop;
namespace TestLanguagePackage
{
public class TestScanner : IScanner
{
private Lexer lex;
private const char memberSelectChar = '.';
public bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo,
ref int state)
{
bool foundToken = false
string token = lex.GetNextToken();
if (token != null)
{
foundToken = true;
char c = token[0];
if (c == memberSelectChar)
{
tokenInfo.Trigger |= TokenTriggers.MemberSelect;
}
}
return foundToken;
}
}
}
구성원 완성의 파서가 지원
구성원 완료를 Source 호출 클래스는 GetDeclarations 메서드. 목록에서 파생 된 클래스에서 구현 해야는 Declarations 클래스입니다. 참조는 Declarations 클래스가 구현 해야 하는 방법에 대 한 자세한 내용은.
파서에서 호출 MemberSelect 또는 MemberSelectAndHighlightBraces 구성원 선택 문자 형식화 된. 지정 된 위치에서 ParseRequest 즉시 해당 멤버를 선택한 후 문자 개체입니다. 파서가 해당 소스 코드의 특정 지점에 구성원 목록에 나타날 수 있는 모든 멤버의 이름을 수집 해야 합니다. 그런 다음 파서가 사용자가 멤버 선택 문자 함께 연결 된 원하는 범위를 결정 하는 현재 줄 구문을 분석 합니다.
멤버를 선택 하기 전에 문자가이 범위 식별자의 형식은 기반으로 합니다. 예를 들어, 주어진 C#의 멤버 변수 languageService 형식을 가진 LanguageService, Languageservice를 입력 합니다. 모든 멤버의 목록을 생성은 LanguageService 클래스입니다. 또한 C#를 입력 합니다. 현재 범위에 있는 클래스의 모든 멤버의 목록을 생성합니다.
예제
채우는 한 가지 방법은 다음 예제는 Declarations 목록입니다. 파서는 선언을 생성 하 고이 호출 하 여 목록에 추가이 코드 가정는 AddDeclaration 방법에의 TestAuthoringScope 클래스.
using System.Collections;
using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.TextManager.Interop;
namespace TestLanguagePackage
{
internal class TestDeclaration
{
public string Name; // Name of declaration
public int TypeImageIndex; // Glyph index
public string Description; // Description of declaration
public TestDeclaration(string name, int typeImageIndex, string description)
{
this.Name = name;
this.TypeImageIndex = typeImageIndex;
this.Description = description;
}
}
//===================================================
internal class TestDeclarations : Declarations
{
private ArrayList declarations;
public TestDeclarations()
: base()
{
declarations = new ArrayList();
}
public void AddDeclaration(TestDeclaration declaration)
{
declarations.Add(declaration);
}
//////////////////////////////////////////////////////////////////////
// Declarations of class methods that must be implemented.
public override int GetCount()
{
// Return the number of declarations to show.
return declarations.Count;
}
public override string GetDescription(int index)
{
// Return the description of the specified item.
string description = "";
if (index >= 0 && index < declarations.Count)
{
description = ((TestDeclaration)declarations[index]).Description;
}
return description;
}
public override string GetDisplayText(int index)
{
// Determine what is displayed in the tool tip list.
string text = null;
if (index >= 0 && index < declarations.Count)
{
text = ((TestDeclaration)declarations[index]).Name;
}
return text;
}
public override int GetGlyph(int index)
{
// Return index of image to display next to the display text.
int imageIndex = -1;
if (index >= 0 && index < declarations.Count)
{
imageIndex = ((TestDeclaration)declarations[index]).TypeImageIndex;
}
return imageIndex;
}
public override string GetName(int index)
{
string name = null;
if (index >= 0 && index < declarations.Count)
{
name = ((TestDeclaration)declarations[index]).Name;
}
return name;
}
}
//===================================================
public class TestAuthoringScope : AuthoringScope
{
private TestDeclarations declarationsList;
public void AddDeclaration(TestDeclaration declaration)
{
if (declaration != null)
{
if (declarationsList == null)
{
declarationsList = new TestDeclarations();
}
declarationsList.AddDeclaration(declaration);
}
}
public override Declarations GetDeclarations(IVsTextView view,
int line,
int col,
TokenInfo info,
ParseReason reason)
{
return declarationsList;
}
/////////////////////////////////////////////////
// Remainder of AuthoringScope methods not shown.
/////////////////////////////////////////////////
}
//===================================================
class TestLanguageService : LanguageService
{
public override AuthoringScope ParseSource(ParseRequest req)
{
TestAuthoringScope scope = new TestAuthoringScope();
if (req.Reason == ParseReason.MemberSelect ||
req.Reason == ParseReason.MemberSelectAndHighlightBraces)
{
// Gather list of declarations based on what the user
// has typed so far. In this example, this list is an array of
// MemberDeclaration objects (a helper class you might implement
// to hold member declarations).
// How this list is gathered is dependent on the parser
// and is not shown here.
MemberDeclarations memberDeclarations;
memberDeclarations = GetDeclarationsForScope();
// Now populate the Declarations list in the authoring scope.
// GetImageIndexBasedOnType() is a helper method you
// might implement to convert a member type to an index into
// the image list returned from the language service.
foreach (MemberDeclaration dec in memberDeclarations)
{
scope.AddDeclaration(new TestDeclaration(
dec.Name,
GetImageIndexBasedOnType(dec.Type),
dec.Description));
}
}
return scope;
}
}
}