public void ConvertSpacesToTabsForDeeplyNestedCode() { var input = new SnippetInput { Body = @"public void MethodName() { if (true) { WriteLine(); } }", ConvertToTabs = true, TabLength = 2 }; var generator = new SnippetGenerator(); var snippet = generator.GetSnippet(input); var lines = Regex.Split(snippet, @"\r?\n"); Assert.EndsWith("\"public void MethodName()\",", lines[3]); Assert.EndsWith("\"{\",", lines[4]); Assert.EndsWith("\"\\t\\tif (true)\",", lines[5]); Assert.EndsWith("\"\\t\\t{\",", lines[6]); Assert.EndsWith("\"\\t\\t\\t\\tWriteLine();\",", lines[7]); Assert.EndsWith("\"\\t\\t}\",", lines[8]); Assert.EndsWith("\"}\"", lines[9]); }
static void Main() { //// RazorEngineを使ったシステムの作成 //// TODO:datファイルを読み込んで、テンプレートとして使用する //// データは最終的にサーバのどこかに置くので、ここでは適当なデータフォルダ作ってアクセス //// TODO:Modelデータを作成する ////OKボタンがクリックされたとき、選択されたファイルを読み取り専用で開く //Console.WriteLine("--------"); //using (var reader = new StreamReader("Template/Test.dat")) //{ // string text = reader.ReadToEnd(); // Console.WriteLine(text); //} //Console.WriteLine("--------"); // スニペットを生成する var sg = new SnippetGenerator(); var data = new SnippetData { // TODO:サンプルデータを作る }; var sb = sg.MakeSnippetXml(data); Console.WriteLine(sb.ToString()); }
public void GeneratePropertySnippet() { var input = new SnippetInput { Name = "Property", Prefix = "prop", Description = "An automatically implemented property.", HasDescription = true, Body = "public ${1:int} ${2:MyProperty} { get; set; }$0" }; var generator = new SnippetGenerator(); var snippet = generator.GetSnippet(input); var lines = Regex.Split(snippet, @"\r?\n"); Assert.Equal("\"Property\": {", lines[0]); Assert.Equal(" \"prefix\": \"prop\",", lines[1]); Assert.Equal(" \"body\": [", lines[2]); Assert.Equal(" \"public ${1:int} ${2:MyProperty} { get; set; }$0\"", lines[3]); Assert.Equal(" ],", lines[4]); Assert.Equal(" \"description\": \"An automatically implemented property.\"", lines[5]); Assert.Equal("}", lines[6]); }
public void SetUp() { snippetGenerator = new SnippetGenerator(true); var loader = new CecilLoader(); loader.IncludeInternalMembers = true; myLib = loader.LoadAssemblyFile(typeof(SnippetGenerationTests).Assembly.Location); mscorlib = loader.LoadAssemblyFile(typeof(object).Assembly.Location); compilation = new SimpleCompilation(myLib, mscorlib); }
public void EscapeDollarSigns() { var input = new SnippetInput { Body = "$name = ${1:name};" }; var snippet = new SnippetGenerator().GetSnippet(input); var lines = Regex.Split(snippet, @"\r?\n"); Assert.Equal(" \"\\\\$name = ${1:name};\"", lines[3]); }
public void GenerateEmptySnippet() { var snippet = new SnippetGenerator().GetSnippet(SnippetInput.Empty); var lines = Regex.Split(snippet, @"\r?\n"); Assert.Equal("\"\": {", lines[0]); Assert.Equal(" \"prefix\": \"\",", lines[1]); Assert.Equal(" \"body\": [", lines[2]); Assert.Equal(" \"\"", lines[3]); Assert.Equal(" ]", lines[4]); Assert.Equal("}", lines[5]); }
private string SetOutput() { // Input.Declaration.Idが""だったらスルー Input.Declarations?.RemoveAll(x => string.IsNullOrWhiteSpace(x.Id)); // Input.Importsが""だったらスルー Input.Imports?.RemoveAll(x => string.IsNullOrWhiteSpace(x)); var generator = new SnippetGenerator(); var xml = generator.MakeSnippetXml(Input); var output = xml.ToString(); ViewData["Output"] = output; return(output); }
public void PreserveSpacesNotUsedForIndentation() { var input = new SnippetInput { Body = " // SOME TEXT", TabLength = 4, ConvertToTabs = true }; var snippet = new SnippetGenerator().GetSnippet(input); var lines = Regex.Split(snippet, @"\r?\n"); Assert.EndsWith("\"\\t// SOME TEXT\"", lines[3]); }
private AutoCompleteResponse MakeAutoCompleteResponse(AutoCompleteRequest request, ISymbol symbol, string completionText, bool preselect, bool isSuggestionMode, bool includeOptionalParams = true) { var displayNameGenerator = new SnippetGenerator(); displayNameGenerator.IncludeMarkers = false; displayNameGenerator.IncludeOptionalParameters = includeOptionalParams; var response = new AutoCompleteResponse(); response.CompletionText = completionText; // TODO: Do something more intelligent here response.DisplayText = displayNameGenerator.Generate(symbol); response.IsSuggestionMode = isSuggestionMode; if (request.WantDocumentationForEveryCompletionResult) { response.Description = DocumentationConverter.ConvertDocumentation(symbol.GetDocumentationCommentXml(), _formattingOptions.NewLine); } if (request.WantReturnType) { response.ReturnType = ReturnTypeFormatter.GetReturnType(symbol); } if (request.WantKind) { response.Kind = symbol.GetKind(); } if (request.WantSnippet) { var snippetGenerator = new SnippetGenerator(); snippetGenerator.IncludeMarkers = true; snippetGenerator.IncludeOptionalParameters = includeOptionalParams; response.Snippet = snippetGenerator.Generate(symbol); } if (request.WantMethodHeader) { response.MethodHeader = displayNameGenerator.Generate(symbol); } response.Preselect = preselect; return(response); }
private AutoCompleteItem MakeAutoCompleteResponse(WantsType wants, ISymbol symbol, string completionText, bool includeOptionalParams = true) { var displayNameGenerator = new SnippetGenerator(); displayNameGenerator.IncludeMarkers = false; displayNameGenerator.IncludeOptionalParameters = includeOptionalParams; var response = new AutoCompleteItem(); response.CompletionText = completionText; // TODO: Do something more intelligent here response.DisplayText = displayNameGenerator.Generate(symbol); if ((wants & WantsType.WantDocumentationForEveryCompletionResult) == WantsType.WantDocumentationForEveryCompletionResult) { response.Description = DocumentationConverter.ConvertDocumentation(symbol.GetDocumentationCommentXml(), "\n" /*_formattingOptions.NewLine*/); } if ((wants & WantsType.WantReturnType) == WantsType.WantReturnType) { response.ReturnType = ReturnTypeFormatter.GetReturnType(symbol); } if ((wants & WantsType.WantKind) == WantsType.WantKind) { response.Kind = symbol.GetKind(); } // if (request.WantSnippet) // { // var snippetGenerator = new SnippetGenerator(); // snippetGenerator.IncludeMarkers = true; // snippetGenerator.IncludeOptionalParameters = includeOptionalParams; // response.Snippet = snippetGenerator.Generate(symbol); // } // if (request.WantMethodHeader) // { // response.MethodHeader = displayNameGenerator.Generate(symbol); // } return(response); }
public void GenerateMultilineSnippet() { var input = new SnippetInput { Name = "Property", Prefix = "prop", Body = "public ${1:int} ${2:MyProperty} { get; set; }$0" + Environment.NewLine + "// Second Line" }; var generator = new SnippetGenerator(); var snippet = generator.GetSnippet(input); var lines = Regex.Split(snippet, @"\r?\n"); Assert.Equal("\"Property\": {", lines[0]); Assert.Equal(" \"prefix\": \"prop\",", lines[1]); Assert.Equal(" \"body\": [", lines[2]); Assert.Equal(" \"public ${1:int} ${2:MyProperty} { get; set; }$0\",", lines[3]); Assert.Equal(" \"// Second Line\"", lines[4]); Assert.Equal(" ]", lines[5]); Assert.Equal("}", lines[6]); }
public void ConvertSpacesToTabs() { var input = new SnippetInput { Name = "Property", Prefix = "prop", Body = " public ${1:int} ${2:MyProperty} { get; set; }$0", ConvertToTabs = true, TabLength = 4 }; var generator = new SnippetGenerator(); var snippet = generator.GetSnippet(input); var lines = Regex.Split(snippet, @"\r?\n"); Assert.Equal("\"Property\": {", lines[0]); Assert.Equal(" \"prefix\": \"prop\",", lines[1]); Assert.Equal(" \"body\": [", lines[2]); Assert.Equal(" \"\\tpublic ${1:int} ${2:MyProperty} { get; set; }$0\"", lines[3]); Assert.Equal(" ]", lines[4]); Assert.Equal("}", lines[5]); }
public IndexModel(SnippetGenerator snippetGenerator, SnippetDeserializer snippetDeserializer) { _snippetGenerator = snippetGenerator; _snippetDeserializer = snippetDeserializer; }