Пример #1
0
		public static SignatureHelpSession TryCreate(SnapshotPoint triggerPosition, SignatureHelpTriggerInfo triggerInfo, Lazy<ISignatureHelpBroker> signatureHelpBroker, ITextView textView) {
			var info = SignatureHelpInfo.Create(triggerPosition.Snapshot);
			if (info == null)
				return null;
			if (triggerInfo.TriggerReason == SignatureHelpTriggerReason.TypeCharCommand) {
				Debug.Assert(triggerInfo.TriggerCharacter != null);
				if (triggerInfo.TriggerCharacter != null && !info.Value.SignatureHelpService.IsTriggerCharacter(triggerInfo.TriggerCharacter.Value))
					return null;
			}
			else if (triggerInfo.TriggerReason == SignatureHelpTriggerReason.RetriggerCommand) {
				if (triggerInfo.TriggerCharacter != null && !info.Value.SignatureHelpService.IsRetriggerCharacter(triggerInfo.TriggerCharacter.Value))
					return null;
			}

			return new SignatureHelpSession(info.Value.SignatureHelpService, signatureHelpBroker, textView);
		}
Пример #2
0
        public async Task <SignatureHelpResult> GetItemsAsync(Document document, int position, SignatureHelpTriggerInfo triggerInfo, CancellationToken cancellationToken = default(CancellationToken))
        {
            var res = await ComputeItemsAsync(signatureHelpProviders, position, triggerInfo.ToSignatureHelpTriggerInfo(), document, cancellationToken).ConfigureAwait(false);

            return(GetSignatureHelpResult(res, document));
        }
Пример #3
0
		void TriggerSession(SignatureHelpTriggerInfo triggerInfo) {
			var position = textView.Caret.Position.BufferPosition;

			if (session == null) {
				session = SignatureHelpSession.TryCreate(position, triggerInfo, signatureHelpBroker, textView);
				if (session == null)
					return;
				session.Disposed += SignatureHelpSession_Disposed;
			}
			session.Restart(position, triggerInfo);
		}
Пример #4
0
		bool RestartCore(SnapshotPoint triggerPosition, SignatureHelpTriggerInfo triggerInfo) {
			var info = SignatureHelpInfo.Create(triggerPosition.Snapshot);
			if (info == null)
				return false;

			Start(info.Value, triggerPosition, triggerInfo);
			return true;
		}
Пример #5
0
		public void Restart(SnapshotPoint triggerPosition, SignatureHelpTriggerInfo triggerInfo) {
			if (!RestartCore(triggerPosition, triggerInfo))
				Dispose();
		}
Пример #6
0
		async Task StartAsync(SignatureHelpInfo info, SnapshotPoint triggerPosition, SignatureHelpTriggerInfo triggerInfo, CancellationToken cancellationToken) {
			// This helps a little to speed up the code
			ProfileOptimizationHelper.StartProfile("roslyn-sighelp-" + info.SignatureHelpService.Language);

			var result = await info.SignatureHelpService.GetItemsAsync(info.Document, triggerPosition.Position, triggerInfo, cancellationToken);
			if (result == null) {
				Dispose();
				return;
			}
			if (cancellationToken.IsCancellationRequested)
				return;
			StartSession(triggerPosition, result);
		}
Пример #7
0
		void Start(SignatureHelpInfo info, SnapshotPoint triggerPosition, SignatureHelpTriggerInfo triggerInfo) {
			CancelFetchItems();
			Debug.Assert(cancellationTokenSource == null);
			cancellationTokenSource = new CancellationTokenSource();
			var cancellationTokenSourceTmp = cancellationTokenSource;
			StartAsync(info, triggerPosition, triggerInfo, cancellationTokenSource.Token)
			.ContinueWith(t => {
				var ex = t.Exception;
				// Free resources
				if (cancellationTokenSource == cancellationTokenSourceTmp)
					CancelFetchItems();
			}, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
		}
Пример #8
0
		async Task InitializeAsync(ITextBuffer buffer, string code, MetadataReference[] refs, string languageName, ISynchronousTagger<IClassificationTag> tagger, CompilationOptions compilationOptions, ParseOptions parseOptions) {
			using (var workspace = new AdhocWorkspace(RoslynMefHostServices.DefaultServices)) {
				var documents = new List<DocumentInfo>();
				var projectId = ProjectId.CreateNewId();
				documents.Add(DocumentInfo.Create(DocumentId.CreateNewId(projectId), "main.cs", null, SourceCodeKind.Regular, TextLoader.From(buffer.AsTextContainer(), VersionStamp.Create())));

				var projectInfo = ProjectInfo.Create(projectId, VersionStamp.Create(), "compilecodeproj", Guid.NewGuid().ToString(), languageName,
					compilationOptions: compilationOptions
							.WithOptimizationLevel(OptimizationLevel.Release)
							.WithPlatform(Platform.AnyCpu)
							.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default),
					parseOptions: parseOptions,
					documents: documents,
					metadataReferences: refs,
					isSubmission: false, hostObjectType: null);
				workspace.AddProject(projectInfo);
				foreach (var doc in documents)
					workspace.OpenDocument(doc.Id);

				buffer.Replace(new Span(0, buffer.CurrentSnapshot.Length), code);

				{
					// Initialize classification code paths
					var spans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length));
					foreach (var tagSpan in tagger.GetTags(spans, CancellationToken.None)) { }
				}

				{
					// Initialize completion code paths
					var info = CompletionInfo.Create(buffer.CurrentSnapshot);
					Debug.Assert(info != null);
					if (info != null) {
						var completionTrigger = CompletionTrigger.Default;
						var completionList = await info.Value.CompletionService.GetCompletionsAsync(info.Value.Document, 0, completionTrigger);
					}
				}

				{
					// Initialize signature help code paths
					var info = SignatureHelpInfo.Create(buffer.CurrentSnapshot);
					Debug.Assert(info != null);
					if (info != null) {
						int sigHelpIndex = code.IndexOf("sighelp");
						Debug.Assert(sigHelpIndex >= 0);
						var triggerInfo = new SignatureHelpTriggerInfo(SignatureHelpTriggerReason.InvokeSignatureHelpCommand);
						var items = await info.Value.SignatureHelpService.GetItemsAsync(info.Value.Document, sigHelpIndex, triggerInfo);
					}
				}

				{
					// Initialize quick info code paths
					var info = QuickInfoState.Create(buffer.CurrentSnapshot);
					Debug.Assert(info != null);
					if (info != null) {
						int quickInfoIndex = code.IndexOf("Equals");
						Debug.Assert(quickInfoIndex >= 0);
						var item = await info.Value.QuickInfoService.GetItemAsync(info.Value.Document, quickInfoIndex);
					}
				}
			}
		}