コード例 #1
0
        internal static ParameterHintingResult CreateProvider(string text)
        {
            string parsedText;
            string editorText;
            int    cursorPosition = text.IndexOf('$');
            int    endPos         = text.IndexOf('$', cursorPosition + 1);

            if (endPos == -1)
            {
                parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1);
            }
            else
            {
                parsedText     = text.Substring(0, cursorPosition) + new string(' ', endPos - cursorPosition) + text.Substring(endPos + 1);
                editorText     = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1);
                cursorPosition = endPos - 1;
            }

            var workspace = new InspectionActionTestBase.TestWorkspace();

            var projectId = ProjectId.CreateNewId();
            //var solutionId = SolutionId.CreateNewId();
            var documentId = DocumentId.CreateNewId(projectId);

            workspace.Open(ProjectInfo.Create(
                               projectId,
                               VersionStamp.Create(),
                               "TestProject",
                               "TestProject",
                               LanguageNames.CSharp,
                               null,
                               null,
                               new CSharpCompilationOptions(
                                   OutputKind.DynamicallyLinkedLibrary,
                                   false,
                                   "",
                                   "",
                                   "Script",
                                   null,
                                   OptimizationLevel.Debug,
                                   false,
                                   false
                                   ),
                               new CSharpParseOptions(
                                   LanguageVersion.CSharp6,
                                   DocumentationMode.None,
                                   SourceCodeKind.Regular,
                                   ImmutableArray.Create("DEBUG", "TEST")
                                   ),
                               new [] {
                DocumentInfo.Create(
                    documentId,
                    "a.cs",
                    null,
                    SourceCodeKind.Regular,
                    TextLoader.From(TextAndVersion.Create(SourceText.From(parsedText), VersionStamp.Create()))
                    )
            },
                               null,
                               InspectionActionTestBase.DefaultMetadataReferences
                               )
                           );

            var engine = new ParameterHintingEngine(workspace, new TestFactory());

            var compilation = workspace.CurrentSolution.GetProject(projectId).GetCompilationAsync().Result;

            if (!workspace.TryApplyChanges(workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(editorText))))
            {
                Assert.Fail();
            }
            var document      = workspace.CurrentSolution.GetDocument(documentId);
            var semanticModel = document.GetSemanticModelAsync().Result;

            return(engine.GetParameterDataProviderAsync(document, semanticModel, cursorPosition).Result);
        }
コード例 #2
0
		internal static ParameterHintingResult CreateProvider(string text)
		{
			string parsedText;
			string editorText;
			int cursorPosition = text.IndexOf('$');
			int endPos = text.IndexOf('$', cursorPosition + 1);
			if (endPos == -1) {
				parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1);
			} else {
				parsedText = text.Substring(0, cursorPosition) + new string(' ', endPos - cursorPosition) + text.Substring(endPos + 1);
				editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1);
				cursorPosition = endPos - 1; 
			}
			
			var workspace = new InspectionActionTestBase.TestWorkspace ();

			var projectId  = ProjectId.CreateNewId();
			//var solutionId = SolutionId.CreateNewId();
			var documentId = DocumentId.CreateNewId(projectId);

			workspace.Open(ProjectInfo.Create(
						projectId,
						VersionStamp.Create(),
						"TestProject",
						"TestProject",
						LanguageNames.CSharp,
						null,
						null,
						new CSharpCompilationOptions (
							OutputKind.DynamicallyLinkedLibrary,
							false,
							"",
							"",
							"Script",
							null,
							OptimizationLevel.Debug,
							false,
							false
						),
						new CSharpParseOptions (
							LanguageVersion.CSharp6,
							DocumentationMode.None,
							SourceCodeKind.Regular,
							ImmutableArray.Create("DEBUG", "TEST")
						),
						new [] {
							DocumentInfo.Create(
								documentId,
								"a.cs",
								null,
								SourceCodeKind.Regular,
								TextLoader.From(TextAndVersion.Create(SourceText.From(parsedText), VersionStamp.Create())) 
							)
						},
						null,
						InspectionActionTestBase.DefaultMetadataReferences
					)
			);
			
			var engine = new ParameterHintingEngine (workspace, new TestFactory ());
			
			var compilation = workspace.CurrentSolution.GetProject(projectId).GetCompilationAsync().Result;
			
			if (!workspace.TryApplyChanges(workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(editorText)))) {
				Assert.Fail();
			}
			var document = workspace.CurrentSolution.GetDocument(documentId);
			var semanticModel = document.GetSemanticModelAsync().Result;
			
			return engine.GetParameterDataProviderAsync(document, semanticModel, cursorPosition).Result;
		}
コード例 #3
0
		internal CompletionList CreateProvider (string input, SourceCodeKind? sourceCodeKind = null, bool usePreviousCharAsTrigger = false)
		{
			int cursorPosition = input.IndexOf ("$$", StringComparison.Ordinal);
			var parsedText = input.Substring (0, cursorPosition) + input.Substring (cursorPosition + 2);

			var workspace = new InspectionActionTestBase.TestWorkspace ();

			var projectId = ProjectId.CreateNewId ();
			//var solutionId = SolutionId.CreateNewId();
			var documentId = DocumentId.CreateNewId (projectId);

			workspace.Open (ProjectInfo.Create (
						projectId,
						VersionStamp.Create (),
						"TestProject",
						"TestProject",
						LanguageNames.CSharp,
						null,
						null,
						new CSharpCompilationOptions (
							OutputKind.DynamicallyLinkedLibrary,
							false,
							"",
							"",
							"Script",
							null,
							OptimizationLevel.Debug,
							false,
							false
						),
						new CSharpParseOptions (
							LanguageVersion.CSharp6,
							DocumentationMode.None,
							SourceCodeKind.Regular,
							ImmutableArray.Create ("DEBUG", "TEST")
						),
						new [] {
							DocumentInfo.Create(
								documentId,
								"a.cs",
								null,
								SourceCodeKind.Regular,
								TextLoader.From(TextAndVersion.Create(SourceText.From(parsedText), VersionStamp.Create()))
							)
						},
						null,
						InspectionActionTestBase.DefaultMetadataReferences
					)
			);
			var engine = new MonoDevelop.CSharp.Completion.RoslynParameterHintingEngine ();

			var compilation = workspace.CurrentSolution.GetProject (projectId).GetCompilationAsync ().Result;

			var document = workspace.CurrentSolution.GetDocument (documentId);
			var semanticModel = document.GetSemanticModelAsync ().Result;

			char triggerChar = cursorPosition > 0 ? document.GetTextAsync ().Result [cursorPosition - 1] : '\0';

			var cs = (CSharpCompletionService)workspace.Services.GetLanguageServices (LanguageNames.CSharp).GetService<CompletionService> ();
			cs.SetTestProviders (CreateCompletionProvider ());

			var trigger = CompletionTrigger.Invoke;
			if (usePreviousCharAsTrigger)
				trigger = new CompletionTrigger (CompletionTriggerKind.Insertion, triggerChar);
			return cs.GetCompletionsAsync (document, cursorPosition, trigger, null, null, default (CancellationToken)).Result;
		}
コード例 #4
0
        internal static MonoDevelop.Ide.CodeCompletion.ParameterHintingResult CreateProvider(string text, bool force = false)
        {
            string parsedText;
            string editorText;
            int    cursorPosition = text.IndexOf('$');
            int    endPos         = text.IndexOf('$', cursorPosition + 1);

            if (endPos == -1)
            {
                parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1);
            }
            else
            {
                parsedText     = text.Substring(0, cursorPosition) + new string(' ', endPos - cursorPosition) + text.Substring(endPos + 1);
                editorText     = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1);
                cursorPosition = endPos - 1;
            }

            var workspace = new InspectionActionTestBase.TestWorkspace();

            var projectId = ProjectId.CreateNewId();
            //var solutionId = SolutionId.CreateNewId();
            var documentId = DocumentId.CreateNewId(projectId);

            workspace.Open(ProjectInfo.Create(
                               projectId,
                               VersionStamp.Create(),
                               "TestProject",
                               "TestProject",
                               LanguageNames.CSharp,
                               null,
                               null,
                               new CSharpCompilationOptions(
                                   OutputKind.DynamicallyLinkedLibrary,
                                   false,
                                   "",
                                   "",
                                   "Script",
                                   null,
                                   OptimizationLevel.Debug,
                                   false,
                                   false
                                   ),
                               new CSharpParseOptions(
                                   LanguageVersion.CSharp6,
                                   DocumentationMode.None,
                                   SourceCodeKind.Regular,
                                   ImmutableArray.Create("DEBUG", "TEST")
                                   ),
                               new [] {
                DocumentInfo.Create(
                    documentId,
                    "a.cs",
                    null,
                    SourceCodeKind.Regular,
                    TextLoader.From(TextAndVersion.Create(SourceText.From(parsedText), VersionStamp.Create()))
                    )
            },
                               null,
                               InspectionActionTestBase.DefaultMetadataReferences
                               )
                           );

            var engine = new MonoDevelop.CSharp.Completion.RoslynParameterHintingEngine();

            var compilation = workspace.CurrentSolution.GetProject(projectId).GetCompilationAsync().Result;

            if (!workspace.TryApplyChanges(workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(editorText))))
            {
                Assert.Fail();
            }
            var document      = workspace.CurrentSolution.GetDocument(documentId);
            var semanticModel = document.GetSemanticModelAsync().Result;

            if (force)
            {
                var workspace1    = TypeSystemService.Workspace;
                var mefExporter   = (IMefHostExportProvider)workspace1.Services.HostServices;
                var helpProviders = mefExporter.GetExports <ISignatureHelpProvider, LanguageMetadata> ()
                                    .FilterToSpecificLanguage(LanguageNames.CSharp).ToList();
                return(engine.GetParameterDataProviderAsync(helpProviders, document, cursorPosition, new SignatureHelpTriggerInfo(SignatureHelpTriggerReason.InvokeSignatureHelpCommand)).Result);
            }
            else
            {
                return(engine.GetParameterDataProviderAsync(document, cursorPosition).Result);
            }
        }