diff options
author | Lluis Sanchez <llsan@microsoft.com> | 2019-02-18 11:26:07 +0300 |
---|---|---|
committer | Lluis Sanchez <llsan@microsoft.com> | 2019-02-18 15:16:03 +0300 |
commit | 4971b9d3563fa4660e022177194263803df9d968 (patch) | |
tree | 8025d8d664cf79378d63e45f0d13df4d08445804 /main/src/addins/AspNet | |
parent | 6c702b0a244a573cb4daef3f748948fedf48ac04 (diff) |
Removed old razor completion code that is not used anymore
Diffstat (limited to 'main/src/addins/AspNet')
7 files changed, 0 insertions, 1096 deletions
diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet.csproj b/main/src/addins/AspNet/MonoDevelop.AspNet.csproj index 0738534865..ff0c562d0b 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet.csproj +++ b/main/src/addins/AspNet/MonoDevelop.AspNet.csproj @@ -183,9 +183,7 @@ <Compile Include="Razor\Parser\RazorState.cs" /> <Compile Include="Razor\Parser\RazorStatementState.cs" /> <Compile Include="Razor\Parser\StateEngineService.cs" /> - <Compile Include="Razor\IRazorCompletionBuilder.cs" /> <Compile Include="Razor\RazorCompletion.cs" /> - <Compile Include="Razor\RazorCSharpEditorExtension.cs" /> <Compile Include="Projects\WebSubtype.cs" /> <Compile Include="Execution\AspNetExecutionCommand.cs" /> <Compile Include="Execution\AspNetExecutionHandler.cs" /> diff --git a/main/src/addins/AspNet/Properties/MonoDevelop.AspNet.addin.xml b/main/src/addins/AspNet/Properties/MonoDevelop.AspNet.addin.xml index 5349b8b9c4..4790e9862a 100644 --- a/main/src/addins/AspNet/Properties/MonoDevelop.AspNet.addin.xml +++ b/main/src/addins/AspNet/Properties/MonoDevelop.AspNet.addin.xml @@ -90,10 +90,6 @@ <ExtensionNode name="Class" />
</ExtensionPoint>
- <ExtensionPoint path = "/MonoDevelop/Razor/CompletionBuilders">
- <ExtensionNode name="Class" />
- </ExtensionPoint>
-
<Extension path = "/MonoDevelop/Ide/ProjectTemplates">
<ProjectTemplate id = "MonoDevelop.AspNet.EmptyProject"
file = "Templates/Projects/EmptyProject.xpt.xml" />
diff --git a/main/src/addins/AspNet/Razor/IRazorCompletionBuilder.cs b/main/src/addins/AspNet/Razor/IRazorCompletionBuilder.cs deleted file mode 100644 index 2beed8acba..0000000000 --- a/main/src/addins/AspNet/Razor/IRazorCompletionBuilder.cs +++ /dev/null @@ -1,111 +0,0 @@ -//
-// IRazorCompletionBuilder.cs
-//
-// Author:
-// Piotr Dowgiallo <sparekd@gmail.com>
-//
-// Copyright (c) 2012 Piotr Dowgiallo
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using MonoDevelop.Ide.CodeCompletion;
-using MonoDevelop.Ide.TypeSystem;
-using MonoDevelop.Ide.Gui;
-using MonoDevelop.Ide.Editor;
-
-namespace MonoDevelop.AspNet.Razor
-{
- // Based on MonoDevelop.AspNet.Gui.ILanguageCompletionBuilder
-
- interface IRazorCompletionBuilder
- {
- bool SupportsLanguage (string language);
- ICompletionWidget CreateCompletionWidget (TextEditor editor, DocumentContext context, UnderlyingDocumentInfo docInfo);
- Task<ICompletionDataList> HandlePopupCompletion (TextEditor editor, DocumentContext context, UnderlyingDocumentInfo docInfo);
- Task<ICompletionDataList> HandleCompletion (TextEditor editor, DocumentContext context, CodeCompletionContext completionContext,
- UnderlyingDocumentInfo docInfo, char currentChar, CancellationToken token);
- Task<MonoDevelop.Ide.CodeCompletion.ParameterHintingResult> HandleParameterCompletion (TextEditor editor, DocumentContext context, CodeCompletionContext completionContext,
- UnderlyingDocumentInfo docInfo, char completionChar);
- // bool GetParameterCompletionCommandOffset (TextEditor editor, DocumentContext context, UnderlyingDocumentInfo docInfo, out int cpos);
- Task<int> GetCurrentParameterIndex (TextEditor editor, DocumentContext context, UnderlyingDocumentInfo docInfo, int startOffset);
- }
-
- public class UnderlyingDocument : Document
- {
- internal ParsedDocument HiddenParsedDocument;
-
- public override ParsedDocument ParsedDocument {
- get { return HiddenParsedDocument; }
- }
-
- public UnderlyingDocument (IWorkbenchWindow window)
- : base (window)
- {
- }
-
- internal Microsoft.CodeAnalysis.Document HiddenAnalysisDocument;
-
- public override Microsoft.CodeAnalysis.Document AnalysisDocument {
- get { return HiddenAnalysisDocument; }
- }
- }
-
- public class UnderlyingDocumentInfo
- {
- public int CaretPosition { get; set; }
- public int OriginalCaretPosition { get; set; }
- public UnderlyingDocument UnderlyingDocument { get; set; }
- }
-
- static class RazorCompletionBuilderService
- {
- static List<IRazorCompletionBuilder> builder = new List<IRazorCompletionBuilder> ();
-
- public static IEnumerable<IRazorCompletionBuilder> Builder {
- get { return builder; }
- }
-
- static RazorCompletionBuilderService ()
- {
- Mono.Addins.AddinManager.AddExtensionNodeHandler ("/MonoDevelop/Razor/CompletionBuilders", delegate (object sender, Mono.Addins.ExtensionNodeEventArgs args)
- {
- switch (args.Change) {
- case Mono.Addins.ExtensionChange.Add:
- builder.Add ((IRazorCompletionBuilder)args.ExtensionObject);
- break;
- case Mono.Addins.ExtensionChange.Remove:
- builder.Remove ((IRazorCompletionBuilder)args.ExtensionObject);
- break;
- }
- });
- }
-
- public static IRazorCompletionBuilder GetBuilder (string language)
- {
- foreach (IRazorCompletionBuilder b in Builder) {
- if (b.SupportsLanguage (language))
- return b;
- }
- return null;
- }
- }
-}
diff --git a/main/src/addins/AspNet/Razor/RazorCSharpEditorExtension.cs b/main/src/addins/AspNet/Razor/RazorCSharpEditorExtension.cs deleted file mode 100644 index f675987cae..0000000000 --- a/main/src/addins/AspNet/Razor/RazorCSharpEditorExtension.cs +++ /dev/null @@ -1,677 +0,0 @@ -// -// RazorCSharpEditorExtension.cs -// -// Author: -// Piotr Dowgiallo <sparekd@gmail.com> -// -// Copyright (c) 2012 Piotr Dowgiallo -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; -using System.Web.Razor.Generator; -using System.Web.Razor.Parser.SyntaxTree; -using Mono.TextEditor; -using MonoDevelop.Core; -using MonoDevelop.Core.Text; -using MonoDevelop.Ide.Editor; -using MonoDevelop.Ide.CodeCompletion; -using MonoDevelop.Ide.Gui; -using MonoDevelop.Ide.TypeSystem; -using MonoDevelop.Xml.Dom; -using MonoDevelop.Xml.Parser; -using MonoDevelop.AspNet.Html; -using MonoDevelop.AspNet.Razor.Dom; -using MonoDevelop.AspNet.Razor.Parser; -using MonoDevelop.Ide.Editor.Extension; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using MonoDevelop.Ide.Editor.Projection; - -namespace MonoDevelop.AspNet.Razor -{ - public class RazorCSharpEditorExtension : BaseHtmlEditorExtension - { - protected RazorCSharpParsedDocument razorDocument; - internal UnderlyingDocumentInfo hiddenInfo; - IRazorCompletionBuilder completionBuilder; - - bool isInCSharpContext; - static readonly Regex DocTypeRegex = new Regex (@"(?:PUBLIC|public)\s+""(?<fpi>[^""]*)""\s+""(?<uri>[^""]*)"""); - - ICompletionWidget defaultCompletionWidget; - MonoDevelop.Ide.Editor.TextEditor defaultEditor; - DocumentContext defaultDocumentContext; - - // RazorSyntaxMode syntaxMode; - - UnderlyingDocument HiddenDoc { - get { return hiddenInfo.UnderlyingDocument; } - } - - RazorPageInfo PageInfo { - get { return razorDocument.PageInfo; } - } - - protected override XmlRootState CreateRootState () - { - return new RazorRootState (); - } - - public override string CompletionLanguage { - get { - return "Razor"; - } - } - - public RazorCSharpEditorExtension () - { - } - - /// <summary> - /// Used by unit tests. - /// </summary> - internal RazorCSharpEditorExtension (MonoDevelop.Ide.Gui.Document doc, RazorCSharpParsedDocument parsedDoc, bool cSharpContext) - { - razorDocument = parsedDoc; - Initialize (doc.Editor, doc); - if (cSharpContext) { - InitializeCodeCompletion (); - SwitchToHidden (); - } - } - - protected override void Initialize () - { - base.Initialize (); - - defaultCompletionWidget = CompletionWidget; - defaultDocumentContext = DocumentContext; - defaultEditor = Editor; - completionBuilder = RazorCompletionBuilderService.GetBuilder ("C#"); - - // defaultEditor.TextChanging += UnderlyingDocument_TextReplacing; - //syntaxMode = new RazorSyntaxMode (Editor, DocumentContext); - //var textEditorData = DocumentContext.GetContent<TextEditorData> (); - //if (textEditorData != null) - // textEditorData.Document.SyntaxMode = syntaxMode; - } - - public override void Dispose () - { - //if (syntaxMode != null) { - // var textEditorData = DocumentContext.GetContent<TextEditorData> (); - // if (textEditorData != null) - // textEditorData.Document.SyntaxMode = null; - // syntaxMode.Dispose (); - // syntaxMode = null; - //} - // defaultEditor.TextChanging -= UnderlyingDocument_TextReplacing; - base.Dispose (); - } - - // Handles text modifications in hidden document - void UnderlyingDocument_TextReplacing (object sender, MonoDevelop.Core.Text.TextChangeEventArgs e) - { - if (razorDocument == null) - return; - - EnsureUnderlyingDocumentSet (); - foreach (var change in e.TextChanges.Reverse ()) { - int off = CalculateCaretPosition (change.Offset); - - if (change.RemovalLength > 0) { - int removalLength = change.RemovalLength; - if (off + removalLength > HiddenDoc.Editor.Length) - removalLength = HiddenDoc.Editor.Length - off; - HiddenDoc.Editor.RemoveText (off, removalLength); - } - if (change.InsertionLength > 0) { - if (isInCSharpContext) { - HiddenDoc.Editor.InsertText (off, change.InsertedText.Text); - HiddenDoc.HiddenAnalysisDocument = HiddenDoc.HiddenAnalysisDocument.WithText (Microsoft.CodeAnalysis.Text.SourceText.From (HiddenDoc.Editor.Text)); - } else // Insert spaces to correctly calculate offsets until next reparse - HiddenDoc.Editor.InsertText (off, new String (' ', change.InsertionLength)); - } - if (codeFragment != null) - codeFragment.EndOffset += (change.InsertionLength - change.RemovalLength); - } - } - - protected override void OnParsedDocumentUpdated () - { - base.OnParsedDocumentUpdated (); - try { - razorDocument = CU as RazorCSharpParsedDocument; - if (razorDocument == null || razorDocument.PageInfo.CSharpSyntaxTree == null) - return; - - CreateDocType (); - - // Don't update C# code in hiddenInfo when: - // 1) We are in a RazorState, and the completion window is visible, - // it'll freeze (or disappear if we call OnCompletionContextChanged). - // 2) We're in the middle of writing a Razor expression - if we're in an incorrect state, - // the generated code migh be behind what we've been already written. - - var state = Tracker.Engine.CurrentState; - if (state is RazorState && CompletionWindowManager.IsVisible || - (!updateNeeded && (state is RazorSpeculativeState || state is RazorExpressionState))) - UpdateHiddenDocument (false); - else { - UpdateHiddenDocument (); - updateNeeded = false; - } - } catch (Exception e) { - LoggingService.LogError ("Error while updating razor completion.", e); - } - } - - void CreateDocType () - { - DocType = new XDocType (MonoDevelop.Ide.Editor.DocumentLocation.Empty); - var matches = DocTypeRegex.Match (razorDocument.PageInfo.DocType); - if (matches.Success) { - DocType.PublicFpi = matches.Groups ["fpi"].Value; - DocType.Uri = matches.Groups ["uri"].Value; - } - } - - void EnsureUnderlyingDocumentSet () - { - if (hiddenInfo == null) - UpdateHiddenDocument (); - } - - void UpdateHiddenDocument (bool updateSourceCode = true) - { - //if (!updateSourceCode && hiddenInfo != null) { - // hiddenInfo.UnderlyingDocument.HiddenParsedDocument = razorDocument.PageInfo.ParsedDocument; - // return; - //} else if (updateSourceCode && hiddenInfo != null) { - // hiddenInfo.UnderlyingDocument.Editor.Text = razorDocument.PageInfo.CSharpCode; - // hiddenInfo.UnderlyingDocument.HiddenParsedDocument = razorDocument.PageInfo.ParsedDocument; - // hiddenInfo.UnderlyingDocument.HiddenAnalysisDocument = razorDocument.PageInfo.AnalysisDocument; - // - // codeFragment = null; - // return; - //} - - //hiddenInfo = new UnderlyingDocumentInfo (); - - //var viewContent = new HiddenTextEditorViewContent (); - //viewContent.Project = DocumentContext.Project; - //viewContent.ContentName = "Generated.cs"; // Use a name with .cs extension to get csharp ambience - //viewContent.Text = razorDocument.PageInfo.CSharpCode; - - //var workbenchWindow = new HiddenWorkbenchWindow (); - //workbenchWindow.ViewContent = viewContent; - //hiddenInfo.UnderlyingDocument = new UnderlyingDocument (workbenchWindow) { - // HiddenParsedDocument = razorDocument.PageInfo.ParsedDocument, - // HiddenAnalysisDocument = razorDocument.PageInfo.AnalysisDocument - //}; - - //// completion window needs this - //Gtk.Widget editor = hiddenInfo.UnderlyingDocument.Editor; - //editor.Parent = ((Gtk.Widget)Editor).Parent; - - //currentMappings = razorDocument.PageInfo.GeneratorResults.DesignTimeLineMappings; - //codeFragment = null; - } - - #region Code completion - - XObject prevNode; - bool updateNeeded; - - public override bool KeyPress (KeyDescriptor descriptor) - { - Tracker.UpdateEngine (); - if (razorDocument == null) - return NonCSharpCompletion (descriptor); - - var n = Tracker.Engine.Nodes.Peek (); - if (prevNode is RazorExpression && !(n is RazorExpression)) - updateNeeded = true; - prevNode = n; - var state = Tracker.Engine.CurrentState; - int off = Editor.CaretOffset; - - char previousChar = off > 0 ? Editor.GetCharAt (off - 1) : ' '; - char beforePrevious = off > 1 ? Editor.GetCharAt (off - 2) : ' '; - - // Determine completion context here, before calling base method to set the context correctly - - // Rule out Razor comments, html, transition sign (@) and e-mail addresses - if (state is RazorCommentState || (previousChar != '@' && !(state is RazorState)) || descriptor.KeyChar == '@' - || (previousChar == '@' && Char.IsLetterOrDigit (beforePrevious))) - return NonCSharpCompletion (descriptor); - - // Determine if we are inside generics - if (previousChar == '<') { - var codeState = state as RazorCodeFragmentState; - if (codeState == null || !codeState.IsInsideGenerics) - return NonCSharpCompletion (descriptor); - } - // Determine whether we begin an html tag or generics - else if (descriptor.KeyChar == '<' && (n is XElement || !Char.IsLetterOrDigit (previousChar))) - return NonCSharpCompletion (descriptor); - // Determine whether we are inside html text or in code - else if (previousChar != '@' && n is XElement && !(state is RazorSpeculativeState) && !(state is RazorExpressionState)) - return NonCSharpCompletion (descriptor); - - return base.KeyPress (descriptor); - // We're in C# context - //InitializeCodeCompletion (); - //SwitchToHidden (); - - //bool result; - //try { - // result = base.KeyPress (descriptor); - // if (/*EnableParameterInsight &&*/ (descriptor.KeyChar == ',' || descriptor.KeyChar == ')') && CanRunParameterCompletionCommand ()) - // base.RunParameterCompletionCommand (); - //} finally { - // SwitchToReal (); - //} - - //return result; - } - - protected void SwitchToHidden () - { - isInCSharpContext = true; - DocumentContext = HiddenDoc; - Editor = HiddenDoc.Editor; - CompletionWidget = completionBuilder.CreateCompletionWidget (defaultEditor, defaultDocumentContext, hiddenInfo); - } - - protected void SwitchToReal () - { - isInCSharpContext = false; - DocumentContext = defaultDocumentContext; - Editor = defaultEditor; - CompletionWidget = defaultCompletionWidget; - } - - bool NonCSharpCompletion (KeyDescriptor descriptor) - { - isInCSharpContext = false; - return base.KeyPress (descriptor); - } - - protected void InitializeCodeCompletion () - { - EnsureUnderlyingDocumentSet (); - hiddenInfo.OriginalCaretPosition = defaultEditor.CaretOffset; - hiddenInfo.CaretPosition = CalculateCaretPosition (); - HiddenDoc.Editor.CaretOffset = hiddenInfo.CaretPosition; - } - - class CodeFragment - { - public int StartOffset { get; set; } - public int StartRealOffset { get; set; } - public int EndOffset { get; set; } - - public CodeFragment () - {} - - public CodeFragment (int startOff, int startRealOff, int endOffset) - { - StartOffset = startOff; - StartRealOffset = startRealOff; - EndOffset = endOffset; - } - } - - int GetDefaultPosition () - { - var root = razorDocument.PageInfo.CSharpSyntaxTree?.GetRoot (); - if (root == null) - return -1; - - var type = root.DescendantNodes ().OfType<TypeDeclarationSyntax> ().FirstOrDefault (); - if (type == null) { - return -1; - } - var method = type.DescendantNodes () - .OfType <MethodDeclarationSyntax> () - .FirstOrDefault (m => m.Identifier.ValueText == "Execute"); - if (method == null) { - return -1; - } - var location = method.Body.GetLocation (); - return location.SourceSpan.Start + 1; - } - - IDictionary<int, GeneratedCodeMapping> currentMappings; - CodeFragment codeFragment; - - int CalculateCaretPosition () - { - return CalculateCaretPosition (defaultEditor.CaretOffset); - } - - int CalculateCaretPosition (int currentOffset) - { - if (codeFragment != null) { - int diff = currentOffset - codeFragment.StartRealOffset; - int off = codeFragment.StartOffset + diff; - if (diff >= 0 && off <= codeFragment.EndOffset) - return off; - } - - KeyValuePair<int, GeneratedCodeMapping> map; - - var defaultPosition = GetDefaultPosition (); - if (defaultPosition < 0) { - defaultPosition = 0; - } - - // If it's first line of code, create a default temp mapping, and use it until next reparse - if (currentMappings.Count == 0) { - string newLine = "\r\n#line 0 \r\n "; - HiddenDoc.Editor.InsertText (defaultPosition, newLine); - map = new KeyValuePair<int, GeneratedCodeMapping> (0, new GeneratedCodeMapping (currentOffset - 1, 0, 0, 0, 0)); - currentMappings.Add (map); - } else { - var result = currentMappings.Where (m => m.Value.StartOffset <= currentOffset); - if (!result.Any ()) - return defaultPosition; - map = result.Last (); - } - - string pattern = "#line " + map.Key + " "; - int pos = HiddenDoc.Editor.Text.IndexOf (pattern, 0, HiddenDoc.Editor.Length, StringComparison.Ordinal); - if (pos == -1 || !map.Value.StartOffset.HasValue) - return defaultPosition; - - int startRealOff = map.Value.StartOffset.Value; - int offDifference = currentOffset - (startRealOff + map.Value.CodeLength); - var line = HiddenDoc.Editor.GetLineByOffset (pos); - int endHiddenOff = line.NextLine.Offset + map.Value.StartGeneratedColumn + map.Value.CodeLength; - - int hiddenOff; - - // If off is inside the map - if (offDifference <= 0) { - int delta = currentOffset - startRealOff; - hiddenOff = line.NextLine.Offset + map.Value.StartGeneratedColumn + delta - 1; - codeFragment = new CodeFragment (hiddenOff, currentOffset, endHiddenOff); - } else { - // It's a new code fragment - create a temp mapping, and use it until next reparse - int key = currentMappings.Last ().Key + 1; - string newLine = "\r\n#line " + key + " \r\n "; - int newOff = endHiddenOff; - - if (HiddenDoc.Editor.GetCharAt (newOff) == '\n') - newOff++; - - // We start a new mapping right after the preceding one, but need to include the difference - // between mapping's start and the current offset - HiddenDoc.Editor.InsertText (newOff, newLine); - HiddenDoc.Editor.InsertText (newOff + newLine.Length, new String (' ', offDifference) + " \r\n"); - - var newMap = new KeyValuePair<int, GeneratedCodeMapping> (key, new GeneratedCodeMapping ( - startRealOff + map.Value.CodeLength, 0, 0, 0, offDifference)); - currentMappings.Add (newMap); - hiddenOff = newOff + newLine.Length + offDifference; - codeFragment = new CodeFragment (newOff + newLine.Length, newMap.Value.StartOffset.Value, - newOff + newLine.Length + offDifference); - } - - return hiddenOff; - } - - public override async System.Threading.Tasks.Task<ICompletionDataList> HandleCodeCompletionAsync (CodeCompletionContext completionContext, CompletionTriggerInfo triggerInfo, System.Threading.CancellationToken token) - { - if (triggerInfo.CompletionTriggerReason == CompletionTriggerReason.CompletionCommand) { - if (hiddenInfo != null && (isInCSharpContext || Tracker.Engine.CurrentState is RazorState) - && !(Tracker.Engine.Nodes.Peek () is XElement)) { - InitializeCodeCompletion (); - return await completionBuilder.HandlePopupCompletion (defaultEditor, defaultDocumentContext, hiddenInfo); - } - } - char previousChar = defaultEditor.CaretOffset > 1 ? defaultEditor.GetCharAt ( - defaultEditor.CaretOffset - 2) : ' '; - if (triggerInfo.CompletionTriggerReason != CompletionTriggerReason.CharTyped) - return null; - // Don't show completion window when directive's name is being typed - var directive = Tracker.Engine.Nodes.Peek () as RazorDirective; - if (directive != null && !directive.FirstBracket.HasValue) - return null; - var completionChar = triggerInfo.TriggerCharacter.Value; - if (hiddenInfo != null && isInCSharpContext) { - var list = (CompletionDataList) await completionBuilder.HandleCompletion (defaultEditor, defaultDocumentContext, completionContext, - hiddenInfo, completionChar, token); - - if (list != null) { - //filter out the C# templates, many of them are not valid - int oldCount = list.Count; - list = FilterCSharpTemplates (list); - int templates = list.Count - oldCount; - - if (previousChar == '@') { - RazorCompletion.AddAllRazorSymbols (list, razorDocument.PageInfo.HostKind); - } - if (templates > 0) { - AddFilteredRazorTemplates (list, previousChar == '@', true); - } - } - return list; - } - - return await base.HandleCodeCompletionAsync (completionContext, triggerInfo, token); - } - - //recreating the list is over 2x as fast as using remove operations, saves typically 10ms - static CompletionDataList FilterCSharpTemplates (CompletionDataList list) - { - var newList = new CompletionDataList () { - AutoCompleteEmptyMatch = list.AutoCompleteEmptyMatch, - AutoCompleteUniqueMatch = list.AutoCompleteUniqueMatch, - AutoSelect = list.AutoSelect, - CloseOnSquareBrackets = list.CloseOnSquareBrackets, - CompletionSelectionMode = list.CompletionSelectionMode, - DefaultCompletionString = list.DefaultCompletionString, - IsSorted = list.IsSorted, - TriggerWordLength = list.TriggerWordLength, - TriggerWordStart = list.TriggerWordStart, - }; - foreach (var l in list) { - var c = l as CompletionData; - if (c == null || (c.Icon.Name != "md-template" && c.Icon.Name != "md-template-surroundwith")) - newList.Add (c); - } - return newList; - } - - static void AddFilteredRazorTemplates (CompletionDataList list, bool atTemplates, bool stripLeadingAt) - { - //add the razor templates then filter them based on whether we follow an @ char, so we don't have - //lots of duplicates - int count = list.Count; - MonoDevelop.Ide.CodeTemplates.CodeTemplateService.AddCompletionDataForMime ("text/x-cshtml", list); - for (int i = count; i < list.Count; i++) { - var d = (CompletionData) list[i]; - if (atTemplates) { - if (d.CompletionText[0] != '@') { - list.RemoveAt (i); - } else if (stripLeadingAt) { - //avoid inserting a double-@, which would not expand correctly - d.CompletionText = d.CompletionText.Substring (1); - } - } else if (d.CompletionText[0] == '@') { - list.RemoveAt (i); - } - } - } - - protected override async Task<ICompletionDataList> HandleCodeCompletion ( - CodeCompletionContext completionContext, bool forced, CancellationToken token) - { - var currentLocation = new MonoDevelop.Ide.Editor.DocumentLocation (completionContext.TriggerLine, completionContext.TriggerLineOffset); - char currentChar = completionContext.TriggerOffset < 1 ? ' ' : Editor.GetCharAt (completionContext.TriggerOffset - 1); - - var codeState = Tracker.Engine.CurrentState as RazorCodeFragmentState; - if (currentChar == '<' && codeState != null) { - if (!codeState.IsInsideParentheses && !codeState.IsInsideGenerics) { - var list = await GetElementCompletions (token); - return list; - } - } else if (currentChar == '>' && Tracker.Engine.CurrentState is RazorCodeFragmentState) - return ClosingTagCompletion (Editor, currentLocation); - - return await base.HandleCodeCompletion (completionContext, forced, token); - } - - //we override to ensure we get parent element name even if there's a razor node in between - protected override async Task<CompletionDataList> GetElementCompletions (CancellationToken token) - { - var list = new CompletionDataList (); - var el = Tracker.Engine.Nodes.OfType<XElement> ().FirstOrDefault (); - var parentName = el == null ? new XName () : el.Name; - - await AddHtmlTagCompletionData (list, Schema, parentName, token); - AddMiscBeginTags (list); - - //FIXME: don't show this after any elements - if (DocType == null) - list.Add ("!DOCTYPE", "md-literal", MonoDevelop.Core.GettextCatalog.GetString ("Document type")); - return list; - } - - /* - public override bool GetParameterCompletionCommandOffset (out int cpos) - { - if (hiddenInfo != null && isInCSharpContext) - return completionBuilder.GetParameterCompletionCommandOffset (defaultEditor, defaultDocumentContext, hiddenInfo, out cpos); - - return base.GetParameterCompletionCommandOffset (out cpos); - }*/ - public override Task<int> GetCurrentParameterIndex (int startOffset, CancellationToken token) - { - if (hiddenInfo != null && isInCSharpContext) { - return completionBuilder.GetCurrentParameterIndex (defaultEditor, defaultDocumentContext, hiddenInfo, startOffset); - } - - return base.GetCurrentParameterIndex (startOffset, token); - } - - public override Task<MonoDevelop.Ide.CodeCompletion.ParameterHintingResult> HandleParameterCompletionAsync ( - CodeCompletionContext completionContext, char completionChar, CancellationToken token) - { - if (hiddenInfo != null && isInCSharpContext) { - return completionBuilder.HandleParameterCompletion (defaultEditor, defaultDocumentContext, completionContext, - hiddenInfo, completionChar); - } - - return base.HandleParameterCompletionAsync (completionContext, completionChar, token); - } - - #endregion - - #region Document outline - - protected override void RefillOutlineStore (ParsedDocument doc, Gtk.TreeStore store) - { - var htmlRoot = razorDocument.PageInfo.HtmlRoot; - var razorRoot = razorDocument.PageInfo.RazorRoot; - var blocks = new List<Block> (); - GetBlocks (razorRoot, blocks); - BuildTreeChildren (store, Gtk.TreeIter.Zero, htmlRoot, blocks); - } - - void GetBlocks (Block root, IList<Block> blocks) - { - foreach (var block in root.Children.Where (n => n.IsBlock).Select (n => n as Block)) { - if (block.Type != BlockType.Markup) - blocks.Add (block); - if (block.Type != BlockType.Helper) - GetBlocks (block, blocks); - } - } - - protected override void InitializeOutlineColumns (MonoDevelop.Ide.Gui.Components.PadTreeView outlineTree) - { - outlineTree.TextRenderer.Xpad = 0; - outlineTree.TextRenderer.Ypad = 0; - outlineTree.AppendColumn ("OutlineNode", outlineTree.TextRenderer, new Gtk.TreeCellDataFunc (OutlineTreeDataFunc)); - } - - protected override void OutlineSelectionChanged (object selection) - { - SelectNode ((RazorOutlineNode)selection); - } - - void BuildTreeChildren (Gtk.TreeStore store, Gtk.TreeIter parent, XContainer p, IList<Block> blocks) - { - foreach (XNode node in p.Nodes) { - var el = node as XElement; - if (el == null) { - var startLoc = node.Region.Begin; - var endLoc = node.Region.End; - var doc = defaultEditor; - - var blocksBetween = blocks.Where (n => n.Start.AbsoluteIndex >= doc.LocationToOffset (startLoc.Line, startLoc.Column) - && n.Start.AbsoluteIndex <= doc.LocationToOffset (endLoc.Line, endLoc.Column)); - - foreach (var block in blocksBetween) { - var outlineNode = new RazorOutlineNode (block) { - Location = new MonoDevelop.Ide.Editor.DocumentRegion (doc.OffsetToLocation (block.Start.AbsoluteIndex), - doc.OffsetToLocation (block.Start.AbsoluteIndex + block.Length)) - }; - if (!parent.Equals (Gtk.TreeIter.Zero)) - store.AppendValues (parent, outlineNode); - else - store.AppendValues (outlineNode); - } - continue; - } - - Gtk.TreeIter childIter; - if (!parent.Equals (Gtk.TreeIter.Zero)) - childIter = store.AppendValues (parent, new RazorOutlineNode(el)); - else - childIter = store.AppendValues (new RazorOutlineNode(el)); - - BuildTreeChildren (store, childIter, el, blocks); - } - } - - void OutlineTreeDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter) - { - Gtk.CellRendererText txtRenderer = (Gtk.CellRendererText)cell; - RazorOutlineNode n = (RazorOutlineNode)model.GetValue (iter, 0); - txtRenderer.Text = n.Name; - } - - void SelectNode (RazorOutlineNode n) - { - EditorSelect (n.Location); - } - - #endregion - } -} diff --git a/main/src/addins/AspNet/Tests/MonoDevelop.AspNet.Tests.csproj b/main/src/addins/AspNet/Tests/MonoDevelop.AspNet.Tests.csproj index 198ab9de75..5e60931e25 100644 --- a/main/src/addins/AspNet/Tests/MonoDevelop.AspNet.Tests.csproj +++ b/main/src/addins/AspNet/Tests/MonoDevelop.AspNet.Tests.csproj @@ -33,11 +33,9 @@ <Compile Include="Razor\Dom\RazorImplicitExpressionsParsingTests.cs" /> <Compile Include="Razor\Dom\RazorParsingTests.cs" /> <Compile Include="Razor\Dom\RazorStatementsParsingTests.cs" /> - <Compile Include="Razor\RazorCompletionTesting.cs" /> <Compile Include="WebForms\WebFormsTesting.cs" /> <Compile Include="WebForms\WebFormsParsingTests.cs" /> <Compile Include="WebForms\WebFormsCompletionTests.cs" /> - <Compile Include="Razor\RazorCompletionTests.cs" /> <Compile Include="Html\HtmlParsingTests.cs" /> <Compile Include="Html\HtmlImplicitClosingTests.cs" /> <Compile Include="Razor\Dom\RazorDocumentTrackerTests.cs" /> diff --git a/main/src/addins/AspNet/Tests/Razor/RazorCompletionTesting.cs b/main/src/addins/AspNet/Tests/Razor/RazorCompletionTesting.cs deleted file mode 100644 index 30c69c5ba6..0000000000 --- a/main/src/addins/AspNet/Tests/Razor/RazorCompletionTesting.cs +++ /dev/null @@ -1,179 +0,0 @@ -// -// RazorCompletionTesting.cs -// -// Author: -// Piotr Dowgiallo <sparekd@gmail.com> -// -// Copyright (c) 2012 Piotr Dowgiallo -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System.Threading;
-using System.Threading.Tasks; -using MonoDevelop.AspNet.Razor;
-using MonoDevelop.Core.Text;
-using MonoDevelop.Ide; -using MonoDevelop.Ide.CodeCompletion;
-using MonoDevelop.Ide.Gui;
-using MonoDevelop.Ide.TypeSystem;
-using MonoDevelop.Projects;
-
-namespace MonoDevelop.AspNet.Tests.Razor
-{ - //largely copied from MonoDevelop.AspNet.Tests.AspNetTesting - - static class RazorCompletionTesting
- { -// TODO: Roslyn port
- static readonly string extension = ".cshtml";
-
- public static Task<CompletionDataList> CreateRazorCtrlSpaceProvider (string text, bool isInCSharpContext)
- {
- return CreateProvider (text, isInCSharpContext, true);
- }
-
- public static async Task<CompletionDataList> CreateProvider (string text, bool isInCSharpContext = false, bool isCtrlSpace = false)
- {
- var ed = await CreateEditor (text, isInCSharpContext);
- int cursorPosition = text.IndexOf ('$');
-
- var ctx = GetCodeCompletionContext (isInCSharpContext, ed.View, ed.Extension.hiddenInfo.UnderlyingDocument);
- - Task<ICompletionDataList> task;
- if (isCtrlSpace) {
- task = ed.Extension.HandleCodeCompletionAsync (ctx, CompletionTriggerInfo.CodeCompletionCommand, default (CancellationToken));
- } else {
- task = ed.Extension.HandleCodeCompletionAsync (ctx, new CompletionTriggerInfo (CompletionTriggerReason.CharTyped, ed.EditorText [cursorPosition - 1]), default (CancellationToken)); - }
- - TypeSystemServiceTestExtensions.UnloadSolution (solution); - if (task != null) { - return await task as CompletionDataList; - } - return null; - }
-
- static CodeCompletionContext GetCodeCompletionContext (bool cSharpContext, TestViewContent sev, UnderlyingDocument underlyingDocument)
- {
- var ctx = new CodeCompletionContext ();
- if (!cSharpContext)
- ctx.TriggerOffset = sev.CursorPosition;
- else
- ctx.TriggerOffset = underlyingDocument.Editor.CaretOffset;
-
- int line, column;
- sev.GetLineColumnFromPosition (ctx.TriggerOffset, out line, out column);
- ctx.TriggerLine = line;
- ctx.TriggerLineOffset = column - 1;
-
- return ctx;
- }
-
- public static async Task<ParameterHintingResult> CreateParameterProvider (string text)
- {
- var ed = await CreateEditor (text, true); -
- int cursorPosition = text.IndexOf ('$');
-
- var ctx = GetCodeCompletionContext (true, ed.View, ed.Extension.hiddenInfo.UnderlyingDocument); - var task = ed.Extension.HandleParameterCompletionAsync (ctx, ed.EditorText[cursorPosition - 1], default(CancellationToken)); - if (task != null) { - return await task; - } - return null;
- }
-
- static Solution solution; - - class EditorInfo - { - public RazorCSharpEditorExtension Extension; - public string EditorText; - public TestViewContent View; - }
-
- static async Task<EditorInfo> CreateEditor (string text, bool isInCSharpContext)
- {
- string parsedText, 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 project = Services.ProjectService.CreateProject ("C#", "AspNetApp");
-
- project.FileName = UnitTests.TestBase.GetTempFile (".csproj");
- string file = UnitTests.TestBase.GetTempFile (extension);
- project.AddFile (file);
-
- var sev = new TestViewContent ();
- sev.Project = project;
- sev.ContentName = file;
- sev.Text = editorText;
- sev.CursorPosition = cursorPosition;
-
- var tww = new TestWorkbenchWindow ();
- tww.ViewContent = sev;
-
- var doc = new TestDocument (tww);
- doc.Editor.FileName = sev.ContentName;
- doc.UpdateProject (project);
-
- solution = new MonoDevelop.Projects.Solution ();
- solution.DefaultSolutionFolder.AddItem (project);
- solution.AddConfiguration ("", true);
- await TypeSystemServiceTestExtensions.LoadSolution (solution);
-
- var parser = new RazorTestingParser {
- Doc = doc
- };
- var options = new ParseOptions {
- Project = project,
- FileName = sev.ContentName,
- Content = new StringTextSource (parsedText)
- };
- var parsedDoc = await parser.Parse (options, default(CancellationToken)) as RazorCSharpParsedDocument;
- doc.HiddenParsedDocument = parsedDoc;
-
- var editorExtension = new RazorCSharpEditorExtension (doc, parsedDoc as RazorCSharpParsedDocument, isInCSharpContext);
- return new EditorInfo { - Extension = editorExtension, - EditorText = editorText, - View = sev - };
- }
- }
-
- public class RazorTestingParser : RazorCSharpParser
- {
- public Document Doc { get; set; }
-
- public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken)
- {
- Doc.Editor.FileName = parseOptions.FileName;
- OpenDocuments.Add (new OpenRazorDocument (Doc.Editor));
- return base.Parse (parseOptions, cancellationToken);
- }
- }
-}
diff --git a/main/src/addins/AspNet/Tests/Razor/RazorCompletionTests.cs b/main/src/addins/AspNet/Tests/Razor/RazorCompletionTests.cs deleted file mode 100644 index 15bd1f5d40..0000000000 --- a/main/src/addins/AspNet/Tests/Razor/RazorCompletionTests.cs +++ /dev/null @@ -1,121 +0,0 @@ -// -// CompletionTests.cs -// -// Author: -// Piotr Dowgiallo <sparekd@gmail.com> -// -// Copyright (c) 2012 Piotr Dowgiallo -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System.Threading.Tasks; -using NUnit.Framework; -using UnitTests; - -namespace MonoDevelop.AspNet.Tests.Razor -{ - [TestFixture] - class RazorCompletionTests : TestBase - { - [Test] - public async Task HtmlTagsCompletion () - { - var provider = await RazorCompletionTesting.CreateProvider ("<$", false); - Assert.IsNotNull (provider); - Assert.IsNotNull (provider.Find ("p")); - Assert.IsNotNull (provider.Find ("div")); - } - - [Test] - public async Task NestedHtmlTagsCompletion () - { - var provider = await RazorCompletionTesting.CreateProvider ("<div><ul><$ </ul></div>", false); - Assert.IsNotNull (provider); - Assert.IsNotNull (provider.Find ("li")); - } - - [Test] - public async Task RazorDirectivesAndStatementsCompletion () - { - var provider = await RazorCompletionTesting.CreateProvider ("@m$", true); - Assert.IsNotNull (provider); - Assert.IsNotNull (provider.Find ("model")); - Assert.IsNotNull (provider.Find ("sessionstate")); - Assert.IsNotNull (provider.Find ("using")); - Assert.IsNotNull (provider.Find ("layout")); - Assert.IsNotNull (provider.Find ("section")); - Assert.IsNotNull (provider.Find ("functions")); - Assert.IsNotNull (provider.Find ("helper")); - Assert.IsNotNull (provider.Find ("inherits")); - - // TODO: Roslyn - the following are not working. - // They work for Ctrl+Space completion but not with completion as you type. -// Assert.IsNotNull (provider.Find ("for")); -// Assert.IsNotNull (provider.Find ("foreach")); -// Assert.IsNotNull (provider.Find ("while")); -// Assert.IsNotNull (provider.Find ("do")); -// Assert.IsNotNull (provider.Find ("lock")); -// Assert.IsNotNull (provider.Find ("switch")); -// Assert.IsNotNull (provider.Find ("if")); -// Assert.IsNotNull (provider.Find ("try")); - } - - [Test] - public async Task CSharpIdentifiersCompletion () - { - var provider = await RazorCompletionTesting.CreateProvider ("@{ i$ }", true); - Assert.IsNotNull (provider); - Assert.IsNotNull (provider.Find ("int")); - Assert.IsNotNull (provider.Find ("var")); - } - - [Test] - public async Task CSharpIdentifiersCtrlSpaceCompletion () - { - var provider = await RazorCompletionTesting.CreateRazorCtrlSpaceProvider ("@{ $ }", true); - Assert.IsNotNull (provider); - Assert.IsNotNull (provider.Find ("int")); - Assert.IsNotNull (provider.Find ("var")); - } - - [Test] - public async Task CSharpMembersCompletion () - { - var provider = await RazorCompletionTesting.CreateProvider ("@{ Char.$ }", true); - Assert.IsNotNull (provider); - Assert.IsNotNull (provider.Find ("IsLetter")); - } - - [Test] - public async Task CSharpMembersCtrlSpaceCompletion () - { - var provider = await RazorCompletionTesting.CreateRazorCtrlSpaceProvider ("@{ Char.Is$ }", true); - Assert.IsNotNull (provider); - Assert.IsNotNull (provider.Find ("IsLetter")); - } - - [Test] - public async Task CSharpParametersCompletion () - { - var provider = await RazorCompletionTesting.CreateParameterProvider ("@{ Char.IsLetter($ }"); - Assert.IsNotNull (provider); - Assert.AreEqual (2, provider.Count); - } - } -} |