Browse Source

Merge remote-tracking branch 'upstream/master'

pull/520/head
JohnnyBravo75 11 years ago
parent
commit
f9ae013d39
  1. 2
      src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.addin
  2. 10
      src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj
  3. 170
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs
  4. 26
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpDotCompletionDataProvider.cs
  5. 58
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpExpressionFinder.cs
  6. 62
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpModelTypeLocater.cs
  7. 68
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpParser.cs
  8. 119
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpResolver.cs
  9. 50
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCompilationUnit.cs
  10. 29
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpLanguageBinding.cs
  11. 9
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs
  12. 24
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionContext.cs
  13. 2
      src/AddIns/Debugger/Debugger.AddIn/Pads/AutoCompleteTextBox.cs
  14. 2
      src/AddIns/Debugger/Debugger.AddIn/Pads/ConsolePad.cs
  15. 8
      src/AddIns/Debugger/Debugger.AddIn/Pads/DebuggerDotCompletion.cs
  16. 2
      src/Main/Base/Project/Src/Services/LanguageBinding/DefaultLanguageBinding.cs
  17. 2
      src/Main/Base/Project/Src/Services/LanguageBinding/ILanguageBinding.cs

2
src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.addin

@ -130,7 +130,7 @@ @@ -130,7 +130,7 @@
</ComplexCondition>
</Path>
<Path name = "/AddIns/DefaultTextEditor/CodeCompletion">
<Path name = "/SharpDevelop/ViewContent/TextEditor/CodeCompletion">
<CodeCompletionBinding id = "RazorCSharp" extensions = ".cshtml" class = "ICSharpCode.AspNet.Mvc.Completion.RazorCSharpCompletionBinding"/>
</Path>

10
src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj

@ -134,14 +134,9 @@ @@ -134,14 +134,9 @@
<Compile Include="Src\AddMvcViewToProjectViewModel.cs" />
<Compile Include="Src\BooleanToVisibilityConverter.cs" />
<Compile Include="Src\CloseDialogBehaviour.cs" />
<Compile Include="Src\Completion\RazorCompilationUnit.cs" />
<Compile Include="Src\Completion\RazorCSharpCompletionBinding.cs" />
<Compile Include="Src\Completion\RazorCSharpDotCompletionDataProvider.cs" />
<Compile Include="Src\Completion\RazorCSharpExpressionFinder.cs" />
<Compile Include="Src\Completion\RazorCSharpModelTypeLocater.cs" />
<Compile Include="Src\Completion\RazorCSharpParser.cs" />
<Compile Include="Src\Completion\RazorCSharpParserModelTypeVisitor.cs" />
<Compile Include="Src\Completion\RazorCSharpResolver.cs" />
<Compile Include="Src\CurrentAppDomain.cs" />
<Compile Include="Src\CurrentAppDomainFactory.cs" />
<Compile Include="Src\Folding\CharacterReader.cs" />
@ -285,6 +280,11 @@ @@ -285,6 +280,11 @@
<Name>ICSharpCode.AvalonEdit</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Libraries\NRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project>
<Name>ICSharpCode.NRefactory.CSharp</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Libraries\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>

170
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs

@ -16,27 +16,149 @@ @@ -16,27 +16,149 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//using System;
//using ICSharpCode.SharpDevelop.Editor;
//using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
//
//namespace ICSharpCode.AspNet.Mvc.Completion
//{
// public class RazorCSharpCompletionBinding : DefaultCodeCompletionBinding
// {
// public RazorCSharpCompletionBinding()
// {
// }
//
// public override CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
// {
// if (ch == '.') {
// new RazorCSharpDotCompletionDataProvider().ShowCompletion(editor);
// return CodeCompletionKeyPressResult.Completed;
// } else if (ch == '(') {
// return base.HandleKeyPress(editor, ch);
// }
// return CodeCompletionKeyPressResult.None;
// }
// }
//}
using System;
using System.IO;
using System.Web.Razor;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
namespace ICSharpCode.AspNet.Mvc.Completion
{
public class RazorCSharpCompletionBinding : ICodeCompletionBinding
{
public bool HandleKeyPressed(ITextEditor editor, char ch)
{
if (ch == '.') {
var binding = CreateBinding(editor);
return binding.HandleKeyPressed(editor, ch);
}
return false;
}
public bool CtrlSpace(ITextEditor editor)
{
return false;
}
public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
{
// We use HandleKeyPressed instead.
return CodeCompletionKeyPressResult.None;
}
ICodeCompletionBinding CreateBinding(ITextEditor editor)
{
return SD.LanguageService.GetLanguageByExtension(".cs")
.CreateCompletionBinding(FindExpressionToComplete(editor), CreateContext(editor));
}
string FindExpressionToComplete(ITextEditor editor)
{
int endOffset = editor.Caret.Offset;
int startOffset = endOffset;
while (startOffset > 0 && IsValidCharacter(editor.Document.GetCharAt(startOffset - 1)))
startOffset--;
return editor.Document.GetText(startOffset, endOffset - startOffset);
}
bool IsValidCharacter(char ch)
{
return Char.IsLetterOrDigit(ch) ||
(ch == '.') ||
(ch == '_');
}
ICodeContext CreateContext(ITextEditor editor)
{
var compilation = SD.ParserService.GetCompilationForFile(editor.FileName);
var project = SD.ProjectService.FindProjectContainingFile(editor.FileName);
var resolveContext = new SimpleTypeResolveContext(compilation.MainAssembly);
var currentTypeDefinition = new DefaultUnresolvedTypeDefinition(project.RootNamespace, Path.GetFileNameWithoutExtension(editor.FileName));
ITypeReference baseTypeReference = new GetClassTypeReference("System.Web.Mvc", "WebViewPage", 1);
baseTypeReference = new ParameterizedTypeReference(baseTypeReference, new[] { FindModelType(editor) });
currentTypeDefinition.BaseTypes.Add(baseTypeReference);
var currentMethod = new DefaultUnresolvedMethod(currentTypeDefinition, "__ContextStub__");
currentMethod.ReturnType = KnownTypeReference.Void;
currentTypeDefinition.Members.Add(currentMethod);
var currentResolvedTypeDef = new DefaultResolvedTypeDefinition(resolveContext, currentTypeDefinition);
var projectContent = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;
var currentFile = new CSharpUnresolvedFile();
currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc");
currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc.Ajax");
currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc.Html");
currentFile.RootUsingScope.AddSimpleUsing("System.Web.Routing");
currentFile.TopLevelTypeDefinitions.Add(currentTypeDefinition);
if (projectContent != null) {
compilation = projectContent.AddOrUpdateFiles(currentFile).CreateCompilation(SD.ParserService.GetCurrentSolutionSnapshot());
}
var context = new CSharpTypeResolveContext(compilation.MainAssembly,
currentFile.RootUsingScope.Resolve(compilation),
currentResolvedTypeDef,
currentMethod.CreateResolved(resolveContext.WithCurrentTypeDefinition(currentResolvedTypeDef)));
return new CSharpResolver(context);
}
ITypeReference FindModelType(ITextEditor editor)
{
ParserResults results = ParseTemplate(editor.Document);
string typeName = GetModelTypeName(results);
if (string.IsNullOrWhiteSpace(typeName))
return KnownTypeReference.Object;
return new CSharpParser().ParseTypeReference(typeName)
.ToTypeReference(NameLookupMode.BaseTypeReference);
}
ParserResults ParseTemplate(ITextSource textBuffer)
{
var host = new RazorEngineHost(new CSharpRazorCodeLanguage());
var engine = new RazorTemplateEngine(host);
return engine.ParseTemplate(textBuffer.CreateReader());
}
string GetModelTypeName(ParserResults results)
{
var visitor = new RazorCSharpParserModelTypeVisitor();
results.Document.Accept(visitor);
return visitor.ModelTypeName;
}
}
static class NRUtils
{
/// <remarks>Does not support type arguments!</remarks>
public static void AddSimpleUsing(this UsingScope scope, string fullName)
{
if (scope == null)
throw new ArgumentNullException("scope");
string[] parts = fullName.Trim().Split('.');
TypeOrNamespaceReference reference = null;
foreach (var part in parts) {
if (reference != null) {
reference = new MemberTypeOrNamespaceReference(reference, part, EmptyList<ITypeReference>.Instance);
} else {
reference = new SimpleTypeOrNamespaceReference(part, EmptyList<ITypeReference>.Instance);
}
}
scope.Usings.AddIfNotNull(reference);
}
}
}

26
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpDotCompletionDataProvider.cs

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// 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;
//
//namespace ICSharpCode.AspNet.Mvc.Completion
//{
// public class RazorCSharpDotCompletionDataProvider : DotCodeCompletionItemProvider
// {
// }
//}

58
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpExpressionFinder.cs

@ -1,58 +0,0 @@ @@ -1,58 +0,0 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// 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 ICSharpCode.SharpDevelop.Dom;
//
//namespace ICSharpCode.AspNet.Mvc.Completion
//{
// public class RazorCSharpExpressionFinder : IExpressionFinder
// {
// public RazorCSharpExpressionFinder()
// {
// }
//
// public ExpressionResult FindExpression(string text, int offset)
// {
// int position = offset - 1;
// while (position > 0 && IsValidCharacter(text[position])) {
// position--;
// }
// position++;
// string expression = text.Substring(position, offset - position);
// return new ExpressionResult(expression);
// }
//
// bool IsValidCharacter(char ch)
// {
// return Char.IsLetterOrDigit(ch) ||
// (ch == '.') ||
// (ch == '_');
// }
//
// public ExpressionResult FindFullExpression(string text, int offset)
// {
// return ExpressionResult.Empty;
// }
//
// public string RemoveLastPart(string expression)
// {
// return expression;
// }
// }
//}

62
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpModelTypeLocater.cs

@ -16,34 +16,34 @@ @@ -16,34 +16,34 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//using System;
//using System.Web.Razor;
//using ICSharpCode.SharpDevelop;
//
//namespace ICSharpCode.AspNet.Mvc.Completion
//{
// public class RazorCSharpModelTypeLocater
// {
// public RazorCSharpModelTypeLocater(ITextBuffer textBuffer)
// {
// ParserResults results = ParseTemplate(textBuffer);
// ModelTypeName = GetModelTypeName(results);
// }
//
// ParserResults ParseTemplate(ITextBuffer textBuffer)
// {
// var host = new RazorEngineHost(new CSharpRazorCodeLanguage());
// var engine = new RazorTemplateEngine(host);
// return engine.ParseTemplate(textBuffer.CreateReader());
// }
//
// string GetModelTypeName(ParserResults results)
// {
// var visitor = new RazorCSharpParserModelTypeVisitor();
// results.Document.Accept(visitor);
// return visitor.ModelTypeName;
// }
//
// public string ModelTypeName { get; private set; }
// }
//}
using System;
using System.Web.Razor;
using ICSharpCode.NRefactory.Editor;
namespace ICSharpCode.AspNet.Mvc.Completion
{
public class RazorCSharpModelTypeLocater
{
public RazorCSharpModelTypeLocater(ITextSource textBuffer)
{
ParserResults results = ParseTemplate(textBuffer);
ModelTypeName = GetModelTypeName(results);
}
ParserResults ParseTemplate(ITextSource textBuffer)
{
var host = new RazorEngineHost(new CSharpRazorCodeLanguage());
var engine = new RazorTemplateEngine(host);
return engine.ParseTemplate(textBuffer.CreateReader());
}
string GetModelTypeName(ParserResults results)
{
var visitor = new RazorCSharpParserModelTypeVisitor();
results.Document.Accept(visitor);
return visitor.ModelTypeName;
}
public string ModelTypeName { get; private set; }
}
}

68
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpParser.cs

@ -1,68 +0,0 @@ @@ -1,68 +0,0 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// 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.IO;
//using ICSharpCode.SharpDevelop;
//using ICSharpCode.SharpDevelop.Dom;
//using ICSharpCode.SharpDevelop.Dom.CSharp;
//using ICSharpCode.SharpDevelop.Project;
//
//namespace ICSharpCode.AspNet.Mvc.Completion
//{
// public class RazorCSharpParser : IParser
// {
// public RazorCSharpParser()
// {
// }
//
// public string[] LexerTags { get; set; }
//
// public LanguageProperties Language {
// get { return LanguageProperties.CSharp; }
// }
//
// public IExpressionFinder CreateExpressionFinder(string fileName)
// {
// return new RazorCSharpExpressionFinder();
// }
//
// public bool CanParse(string fileName)
// {
// return Path.GetExtension(fileName).Equals(".cshtml", StringComparison.OrdinalIgnoreCase);
// }
//
// public bool CanParse(IProject project)
// {
// return project.Language == "C#";
// }
//
// public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContent)
// {
// var modelTypeLocater = new RazorCSharpModelTypeLocater(fileContent);
// return new RazorCompilationUnit(projectContent) {
// ModelTypeName = modelTypeLocater.ModelTypeName
// };
// }
//
// public IResolver CreateResolver()
// {
// return new RazorCSharpResolver();
// }
// }
//}

119
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpResolver.cs

@ -1,119 +0,0 @@ @@ -1,119 +0,0 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// 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 ICSharpCode.NRefactory.TypeSystem;
//
//namespace ICSharpCode.AspNet.Mvc.Completion
//{
// public class RazorCSharpResolver : IResolver
// {
// NRefactoryResolver resolver = new NRefactoryResolver(LanguageProperties.CSharp);
//
// public ResolveResult Resolve(ExpressionResult expressionResult, ParseInformation parseInfo, string fileContent)
// {
// ParseInformation parseInfoWithWebViewPageClass = CreateParseInformationWithWebViewPageClass(parseInfo);
// expressionResult.Region = GetRegionInMiddleOfWebViewPageClass();
// return resolver.Resolve(expressionResult, parseInfoWithWebViewPageClass, fileContent);
// }
//
// ParseInformation CreateParseInformationWithWebViewPageClass(ParseInformation parseInfo)
// {
// RazorCompilationUnit compilationUnit = RazorCompilationUnit.CreateFromParseInfo(parseInfo);
// AddDefaultUsings(compilationUnit);
// AddWebViewPageClass(compilationUnit);
// return new ParseInformation(compilationUnit);
// }
//
// void AddDefaultUsings(ICompilationUnit compilationUnit)
// {
// AddUsing("System.Web.Mvc", compilationUnit);
// AddUsing("System.Web.Mvc.Ajax", compilationUnit);
// AddUsing("System.Web.Mvc.Html", compilationUnit);
// AddUsing("System.Web.Routing", compilationUnit);
// }
//
// void AddUsing(string name, ICompilationUnit compilationUnit)
// {
// DefaultUsing defaultUsing = CreateUsing(name, compilationUnit.ProjectContent);
// compilationUnit.UsingScope.Usings.Add(defaultUsing);
// }
//
// DefaultUsing CreateUsing(string namespaceName, IProjectContent projectContent)
// {
// var defaultUsing = new DefaultUsing(projectContent);
// defaultUsing.Usings.Add(namespaceName);
// return defaultUsing;
// }
//
// void AddWebViewPageClass(RazorCompilationUnit compilationUnit)
// {
// DefaultClass webViewPageClass = CreateWebViewPageClass(compilationUnit);
// compilationUnit.Classes.Add(webViewPageClass);
// }
//
// DefaultClass CreateWebViewPageClass(RazorCompilationUnit compilationUnit)
// {
// var webViewPageClass = new DefaultClass(compilationUnit, "RazorWebViewPage") {
// Region = new DomRegion(1, 0, 3, 0)
// };
// IReturnType modelType = GetModelReturnType(compilationUnit);
// AddWebViewPageBaseClass(webViewPageClass, modelType);
// return webViewPageClass;
// }
//
// IReturnType GetModelReturnType(RazorCompilationUnit compilationUnit)
// {
// IClass modelType = GetClassIfTypeNameIsNotEmpty(compilationUnit.ProjectContent, compilationUnit.ModelTypeName);
// if (modelType != null) {
// return modelType.DefaultReturnType;
// }
// return new DynamicReturnType(compilationUnit.ProjectContent);
// }
//
// IClass GetClassIfTypeNameIsNotEmpty(IProjectContent projectContent, string modelTypeName)
// {
// if (!String.IsNullOrEmpty(modelTypeName)) {
// return projectContent.GetClass(modelTypeName, 0);
// }
// return null;
// }
//
// void AddWebViewPageBaseClass(DefaultClass webViewPageClass, IReturnType modelType)
// {
// IClass webViewPageBaseClass = webViewPageClass.ProjectContent.GetClass("System.Web.Mvc.WebViewPage", 1);
// if (webViewPageBaseClass != null) {
// IReturnType returnType = GetWebViewPageBaseClassReturnType(webViewPageBaseClass, modelType);
// webViewPageClass.BaseTypes.Add(returnType);
// }
// }
//
// IReturnType GetWebViewPageBaseClassReturnType(IClass webViewPageBaseClass, IReturnType modelType)
// {
// var typeArguments = new List<IReturnType>();
// typeArguments.Add(modelType);
// return new ConstructedReturnType(webViewPageBaseClass.DefaultReturnType, typeArguments);
// }
//
// DomRegion GetRegionInMiddleOfWebViewPageClass()
// {
// return new DomRegion(2, 0, 2, 0);
// }
// }
//}

50
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCompilationUnit.cs

@ -1,50 +0,0 @@ @@ -1,50 +0,0 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// 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 ICSharpCode.NRefactory.TypeSystem;
//using ICSharpCode.SharpDevelop.Parser;
//
//namespace ICSharpCode.AspNet.Mvc.Completion
//{
// public class RazorCompilationUnit : DefaultCompilationUnit
// {
// public RazorCompilationUnit(IProjectContent projectContent)
// : base(projectContent)
// {
// }
//
// public static RazorCompilationUnit CreateFromParseInfo(ParseInformation parseInformation)
// {
// return new RazorCompilationUnit(parseInformation.CompilationUnit.ProjectContent) {
// ModelTypeName = GetModelTypeName(parseInformation.CompilationUnit)
// };
// }
//
// static string GetModelTypeName(ICompilationUnit compilationUnit)
// {
// var originalRazorCompilationUnit = compilationUnit as RazorCompilationUnit;
// if (originalRazorCompilationUnit != null) {
// return originalRazorCompilationUnit.ModelTypeName;
// }
// return String.Empty;
// }
//
// public string ModelTypeName { get; set; }
// }
//}

29
src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpLanguageBinding.cs

@ -55,35 +55,26 @@ namespace CSharpBinding @@ -55,35 +55,26 @@ namespace CSharpBinding
this.container.AddService(typeof(System.CodeDom.Compiler.CodeDomProvider), new Microsoft.CSharp.CSharpCodeProvider());
}
public override ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, FileName fileName, TextLocation location, ICodeContext context)
public override ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, ICodeContext context)
{
if (fileName == null)
throw new ArgumentNullException("fileName");
if (context == null)
throw new ArgumentNullException("context");
string content = GeneratePartialClassContextStub(fileName, location, context);
string content = GeneratePartialClassContextStub(context);
const string caretPoint = "$__Caret_Point__$;";
int caretOffset = content.IndexOf(caretPoint, StringComparison.Ordinal) + expressionToComplete.Length;
SD.Log.DebugFormatted("context used for dot completion: {0}", content.Replace(caretPoint, "$" + expressionToComplete + "|$"));
var doc = new ReadOnlyDocument(content.Replace(caretPoint, expressionToComplete));
return new CSharpCompletionBinding(fileName, doc.GetLocation(caretOffset), doc.CreateSnapshot());
return new CSharpCompletionBinding(context, doc.GetLocation(caretOffset), doc.CreateSnapshot());
}
static string GeneratePartialClassContextStub(FileName fileName, TextLocation location, ICodeContext context)
static string GeneratePartialClassContextStub(ICodeContext context)
{
var compilation = SD.ParserService.GetCompilationForFile(fileName);
var file = SD.ParserService.GetExistingUnresolvedFile(fileName);
if (compilation == null || file == null)
return "";
var unresolvedMember = file.GetMember(location);
if (unresolvedMember == null)
return "";
var member = unresolvedMember.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
var member = context.CurrentMember;
if (member == null)
return "";
var builder = new TypeSystemAstBuilder();
MethodDeclaration decl;
if (unresolvedMember is IMethod) {
if (member is IMethod) {
// If it's a method, convert it directly (including parameters + type parameters)
decl = (MethodDeclaration)builder.ConvertEntity(member);
} else {
@ -97,11 +88,11 @@ namespace CSharpBinding @@ -97,11 +88,11 @@ namespace CSharpBinding
}
decl.Name = "__DebuggerStub__";
decl.ReturnType = builder.ConvertType(member.ReturnType);
decl.Modifiers = unresolvedMember.IsStatic ? Modifiers.Static : Modifiers.None;
decl.Modifiers = member.IsStatic ? Modifiers.Static : Modifiers.None;
// Make the method look like an explicit interface implementation so that it doesn't appear in CC
decl.PrivateImplementationType = new SimpleType("__DummyType__");
decl.Body = GenerateBodyFromContext(builder, context.LocalVariables.ToArray());
return WrapInType(unresolvedMember.DeclaringTypeDefinition, decl).ToString();
return WrapInType(context.CurrentTypeDefinition, decl).ToString();
}
static BlockStatement GenerateBodyFromContext(TypeSystemAstBuilder builder, IVariable[] variables)
@ -113,7 +104,7 @@ namespace CSharpBinding @@ -113,7 +104,7 @@ namespace CSharpBinding
return body;
}
static AstNode WrapInType(IUnresolvedTypeDefinition entity, EntityDeclaration decl)
static AstNode WrapInType(ITypeDefinition entity, EntityDeclaration decl)
{
if (entity == null)
return decl;
@ -137,7 +128,7 @@ namespace CSharpBinding @@ -137,7 +128,7 @@ namespace CSharpBinding
};
}
static ClassType GetClassType(IUnresolvedTypeDefinition entity)
static ClassType GetClassType(ITypeDefinition entity)
{
switch (entity.Kind) {
case TypeKind.Interface:

9
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs

@ -26,6 +26,7 @@ using ICSharpCode.NRefactory.CSharp.Resolver; @@ -26,6 +26,7 @@ using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.Completion;
using ICSharpCode.NRefactory.CSharp.Completion;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
@ -35,7 +36,7 @@ namespace CSharpBinding.Completion @@ -35,7 +36,7 @@ namespace CSharpBinding.Completion
{
public class CSharpCompletionBinding : ICodeCompletionBinding
{
FileName contextFileName;
ICodeContext context;
TextLocation currentLocation;
ITextSource fileContent;
@ -44,9 +45,9 @@ namespace CSharpBinding.Completion @@ -44,9 +45,9 @@ namespace CSharpBinding.Completion
{
}
public CSharpCompletionBinding(FileName contextFileName, TextLocation currentLocation, ITextSource fileContent)
public CSharpCompletionBinding(ICodeContext context, TextLocation currentLocation, ITextSource fileContent)
{
this.contextFileName = contextFileName;
this.context = context;
this.currentLocation = currentLocation;
this.fileContent = fileContent;
}
@ -75,7 +76,7 @@ namespace CSharpBinding.Completion @@ -75,7 +76,7 @@ namespace CSharpBinding.Completion
if (fileContent == null) {
completionContext = CSharpCompletionContext.Get(editor);
} else {
completionContext = CSharpCompletionContext.Get(editor, fileContent, currentLocation, contextFileName);
completionContext = CSharpCompletionContext.Get(editor, context, currentLocation, fileContent);
}
if (completionContext == null)
return false;

24
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionContext.cs

@ -61,38 +61,24 @@ namespace CSharpBinding.Completion @@ -61,38 +61,24 @@ namespace CSharpBinding.Completion
return new CSharpCompletionContext(editor, parseInfo.SyntaxTree.ConditionalSymbols, compilation, projectContent, editor.Document, parseInfo.UnresolvedFile, editor.Caret.Location);
}
public static CSharpCompletionContext Get(ITextEditor editor, ITextSource fileContent, TextLocation currentLocation, FileName fileName)
public static CSharpCompletionContext Get(ITextEditor editor, ICodeContext context, TextLocation currentLocation, ITextSource fileContent)
{
IDocument document = new ReadOnlyDocument(fileContent);
// Don't require the very latest parse information, an older cached version is OK.
var parseInfo = SD.ParserService.GetCachedParseInformation(fileName) as CSharpFullParseInformation;
if (parseInfo == null) {
parseInfo = SD.ParserService.Parse(fileName) as CSharpFullParseInformation;
}
if (parseInfo == null)
return null;
var project = SD.ProjectService.FindProjectContainingFile(fileName)as CSharpProject;
if (project == null)
return null;
var solutionSnapshot = SD.ParserService.GetCurrentSolutionSnapshot();
var projectContent = solutionSnapshot.GetProjectContent(project);
var projectContent = context.Compilation.MainAssembly.UnresolvedAssembly as IProjectContent;
if (projectContent == null)
return null;
CSharpParser parser = new CSharpParser(project.CompilerSettings);
CSharpParser parser = new CSharpParser();
parser.GenerateTypeSystemMode = false;
SyntaxTree cu = parser.Parse(fileContent, Path.GetRandomFileName() + ".cs");
cu.Freeze();
CSharpUnresolvedFile unresolvedFile = cu.ToTypeSystem();
ICompilation compilation = projectContent.AddOrUpdateFiles(unresolvedFile).CreateCompilation(solutionSnapshot);
ICompilation compilation = projectContent.AddOrUpdateFiles(unresolvedFile).CreateCompilation(SD.ParserService.GetCurrentSolutionSnapshot());
return new CSharpCompletionContext(editor, parseInfo.SyntaxTree.ConditionalSymbols, compilation, projectContent, document, unresolvedFile, currentLocation);
return new CSharpCompletionContext(editor, EmptyList<string>.Instance, compilation, projectContent, document, unresolvedFile, currentLocation);
}
private CSharpCompletionContext(ITextEditor editor, IList<string> conditionalSymbols, ICompilation compilation, IProjectContent projectContent, IDocument document, CSharpUnresolvedFile unresolvedFile, TextLocation caretLocation)

2
src/AddIns/Debugger/Debugger.AddIn/Pads/AutoCompleteTextBox.cs

@ -134,7 +134,7 @@ namespace Debugger.AddIn.Pads.Controls @@ -134,7 +134,7 @@ namespace Debugger.AddIn.Pads.Controls
ContextTextLocation = new TextLocation(frame.NextStatement.StartLine, frame.NextStatement.StartColumn);
}
if (ContextFileName == null) return;
var binding = DebuggerDotCompletion.PrepareDotCompletion(editor.Text.Substring(0, editor.CaretOffset), ContextFileName, ContextTextLocation, SD.ParserService.ResolveContext(ContextFileName, ContextTextLocation));
var binding = DebuggerDotCompletion.PrepareDotCompletion(editor.Text.Substring(0, editor.CaretOffset), SD.ParserService.ResolveContext(ContextFileName, ContextTextLocation));
if (binding == null) return;
binding.HandleKeyPressed(editorAdapter, '.');
} else {

2
src/AddIns/Debugger/Debugger.AddIn/Pads/ConsolePad.cs

@ -88,7 +88,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -88,7 +88,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
{
var fileName = new ICSharpCode.Core.FileName(frame.NextStatement.Filename);
var textLocation = new TextLocation(frame.NextStatement.StartLine, frame.NextStatement.StartColumn);
var binding = DebuggerDotCompletion.PrepareDotCompletion(currentText, fileName, textLocation, SD.ParserService.ResolveContext(fileName, textLocation));
var binding = DebuggerDotCompletion.PrepareDotCompletion(currentText, SD.ParserService.ResolveContext(fileName, textLocation));
if (binding == null) return;
binding.HandleKeyPressed(console.TextEditor, '.');
}

8
src/AddIns/Debugger/Debugger.AddIn/Pads/DebuggerDotCompletion.cs

@ -41,12 +41,10 @@ namespace Debugger.AddIn.Pads.Controls @@ -41,12 +41,10 @@ namespace Debugger.AddIn.Pads.Controls
return !errors.Any();
}
public static ICodeCompletionBinding PrepareDotCompletion(string expressionToComplete, FileName fileName, TextLocation location, ICodeContext context)
public static ICodeCompletionBinding PrepareDotCompletion(string expressionToComplete, ICodeContext context)
{
var lang = SD.LanguageService.GetLanguageByFileName(fileName);
if (lang == null)
return null;
return lang.CreateCompletionBinding(expressionToComplete, fileName, location, context);
return SD.LanguageService.GetLanguageByExtension(".cs")
.CreateCompletionBinding(expressionToComplete, context);
}
}
}

2
src/Main/Base/Project/Src/Services/LanguageBinding/DefaultLanguageBinding.cs

@ -75,7 +75,7 @@ namespace ICSharpCode.SharpDevelop @@ -75,7 +75,7 @@ namespace ICSharpCode.SharpDevelop
}
}
public virtual ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, FileName fileName, TextLocation location, ICodeContext context)
public virtual ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, ICodeContext context)
{
throw new NotSupportedException();
}

2
src/Main/Base/Project/Src/Services/LanguageBinding/ILanguageBinding.cs

@ -65,6 +65,6 @@ namespace ICSharpCode.SharpDevelop @@ -65,6 +65,6 @@ namespace ICSharpCode.SharpDevelop
/// <summary>
/// Creates a completion binding for a given expression and context.
/// </summary>
ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, FileName fileName, TextLocation location, ICodeContext context);
ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, ICodeContext context);
}
}

Loading…
Cancel
Save