diff options
Diffstat (limited to 'main/src/addins/CSharpBinding')
21 files changed, 346 insertions, 220 deletions
diff --git a/main/src/addins/CSharpBinding/AspNet/ASPNetReferenceFinder.cs b/main/src/addins/CSharpBinding/AspNet/ASPNetReferenceFinder.cs index 1484fe7b1d..ec6553f68a 100644 --- a/main/src/addins/CSharpBinding/AspNet/ASPNetReferenceFinder.cs +++ b/main/src/addins/CSharpBinding/AspNet/ASPNetReferenceFinder.cs @@ -58,7 +58,7 @@ namespace MonoDevelop.CSharp.Refactoring // yield return new DomRegion (fileName, loc.Line, loc.Column, loc.Line, loc.Column + result.Name.Lenhth); // } } - public override IEnumerable<MemberReference> FindReferences (MonoDevelop.Projects.Project project, IProjectContent content, IEnumerable<FilePath> files, IProgressMonitor monitor, IEnumerable<object> searchedMembers) + public override IEnumerable<MemberReference> FindReferences (MonoDevelop.Projects.Project project, IProjectContent content, IEnumerable<FilePath> files, ProgressMonitor monitor, IEnumerable<object> searchedMembers) { // TODO: Type system conversion. yield break; // var editor = TextFileProvider.Instance.GetTextEditorData (fileName); diff --git a/main/src/addins/CSharpBinding/Autotools/CSharpAutotoolsSetup.cs b/main/src/addins/CSharpBinding/Autotools/CSharpAutotoolsSetup.cs index 3e08162ea7..9df0ae112b 100644 --- a/main/src/addins/CSharpBinding/Autotools/CSharpAutotoolsSetup.cs +++ b/main/src/addins/CSharpBinding/Autotools/CSharpAutotoolsSetup.cs @@ -43,7 +43,7 @@ namespace CSharpBinding.Autotools if ( config == null ) return ""; CSharpCompilerParameters parameters = (CSharpCompilerParameters) config.CompilationParameters; - CSharpProjectParameters projectParameters = (CSharpProjectParameters) config.ProjectParameters; + ICSharpProject projectParameters = config.ParentItem.GetService<ICSharpProject> (); StringWriter writer = new StringWriter(); diff --git a/main/src/addins/CSharpBinding/CSharpBinding.addin.xml b/main/src/addins/CSharpBinding/CSharpBinding.addin.xml index 8ac2fe8f96..6531dabcbe 100644 --- a/main/src/addins/CSharpBinding/CSharpBinding.addin.xml +++ b/main/src/addins/CSharpBinding/CSharpBinding.addin.xml @@ -10,21 +10,18 @@ </Extension> <Extension path = "/MonoDevelop/ProjectModel/MSBuildItemTypes"> - <DotNetProject + <DotNetProjectType language="C#" extension="csproj" guid="{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" import="$(MSBuildBinPath)\Microsoft.CSharp.targets" - resourceHandler="MonoDevelop.CSharp.Project.CSharpResourceIdBuilder" + type="MonoDevelop.CSharp.Project.CSharpProject" /> + </Extension> + + <Extension path = "/MonoDevelop/ProjectModel/ProjectModelExtensions"> <Condition id="MSBuildTargetIsAvailable" target="$(MSBuildExtensionsPath)\Microsoft\Portable\v4.0\Microsoft.Portable.CSharp.targets"> - <DotNetProjectSubtype - guid="{786C830F-07A1-408B-BD7F-6EE04809D6DB}" - type="MonoDevelop.Projects.PortableDotNetProject" - useXBuild="true"> - <AddImport language="C#" projects="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> - <RemoveImport language="C#" projects="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> - </DotNetProjectSubtype> + <ProjectFlavor guid="{786C830F-07A1-408B-BD7F-6EE04809D6DB}" type="MonoDevelop.CSharp.Project.PortableCSharpProjectFlavor" /> </Condition> </Extension> diff --git a/main/src/addins/CSharpBinding/CSharpBinding.csproj b/main/src/addins/CSharpBinding/CSharpBinding.csproj index 180eb11cbd..5c449f40fb 100644 --- a/main/src/addins/CSharpBinding/CSharpBinding.csproj +++ b/main/src/addins/CSharpBinding/CSharpBinding.csproj @@ -222,7 +222,6 @@ <Compile Include="MonoDevelop.CSharp.Formatting\CSharpFormattingPolicyPanel.cs" /> <Compile Include="MonoDevelop.CSharp.Formatting\CSharpFormatter.cs" /> <Compile Include="MonoDevelop.CSharp.Project\CSharpCompilerParameters.cs" /> - <Compile Include="MonoDevelop.CSharp.Project\CSharpProjectParameters.cs" /> <Compile Include="MonoDevelop.CSharp.Project\CSharpResourceIdBuilder.cs" /> <Compile Include="MonoDevelop.CSharp.Project\CodeGenerationPanel.cs" /> <Compile Include="MonoDevelop.CSharp.Project\CompilerOptionsPanelWidget.cs" /> @@ -313,6 +312,8 @@ <Compile Include="MonoDevelop.CSharp.CodeGeneration\ExportCodeGenerator.cs" /> <Compile Include="MonoDevelop.CSharp.Completion\MonoCSharpCompletionEngine.cs" /> <Compile Include="MonoDevelop.CSharp.Completion\ProtocolCompletionData.cs" /> + <Compile Include="MonoDevelop.CSharp.Project\CSharpProjectExtension.cs" /> + <Compile Include="MonoDevelop.CSharp.Project\PortableCSharpProjectFlavor.cs" /> </ItemGroup> <ItemGroup> <None Include="Makefile.am" /> diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs index cdac91156d..316fa9aab4 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs @@ -58,6 +58,7 @@ using MonoDevelop.CSharp.Project; using MonoDevelop.CSharp.Formatting; using MonoDevelop.CSharp.Refactoring.CodeActions; using MonoDevelop.Refactoring; +using System.Xml; namespace MonoDevelop.CSharp.Completion { @@ -147,13 +148,16 @@ namespace MonoDevelop.CSharp.Completion public CSharpCompletionTextEditorExtension () { } - + + bool addEventHandlersInInitialization = true; + /// <summary> /// Used in testing environment. /// </summary> [System.ComponentModel.Browsable(false)] - public CSharpCompletionTextEditorExtension (MonoDevelop.Ide.Gui.Document doc) : this () + public CSharpCompletionTextEditorExtension (MonoDevelop.Ide.Gui.Document doc, bool addEventHandlersInInitialization = true) : this () { + this.addEventHandlersInInitialization = addEventHandlersInInitialization; Initialize (doc); } @@ -165,10 +169,12 @@ namespace MonoDevelop.CSharp.Completion this.Unit = parsedDocument.GetAst<SyntaxTree> (); this.UnresolvedFileCompilation = Document.Compilation; this.CSharpUnresolvedFile = parsedDocument.ParsedFile as CSharpUnresolvedFile; - document.Editor.Caret.PositionChanged += HandlePositionChanged; + if (addEventHandlersInInitialization) + document.Editor.Caret.PositionChanged += HandlePositionChanged; } - - Document.DocumentParsed += HandleDocumentParsed; + + if (addEventHandlersInInitialization) + Document.DocumentParsed += HandleDocumentParsed; } CancellationTokenSource src = new CancellationTokenSource (); diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpTextEditorIndentation.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpTextEditorIndentation.cs index 87898df7e1..fce4666569 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpTextEditorIndentation.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpTextEditorIndentation.cs @@ -580,6 +580,7 @@ namespace MonoDevelop.CSharp.Formatting int lastNonWsOffset = caretOffset; char lastNonWsChar = '\0'; outOffset = caretOffset; + int max = curLine.EndOffset; int end = caretOffset; @@ -595,69 +596,22 @@ namespace MonoDevelop.CSharp.Formatting return false; } - bool isInString = false, isInChar = false, isVerbatimString = false; - bool isInLineComment = false, isInBlockComment = false; - bool firstChar = true; - for (int pos = caretOffset; pos < max; pos++) { - if (pos == caretOffset) { - if (isInString || isInChar || isVerbatimString || isInLineComment || isInBlockComment) { - outOffset = pos; - return true; - } - } - char ch = data.Document.GetCharAt (pos); - switch (ch) { - case '}': - if (firstChar && !IsSemicolonalreadyPlaced (data, caretOffset)) - return false; - break; - case '/': - if (isInBlockComment) { - isInBlockComment &= pos <= 0 || data.Document.GetCharAt (pos - 1) != '*'; - } else if (!isInString && !isInChar && pos + 1 < max) { - char nextChar = data.Document.GetCharAt (pos + 1); - if (nextChar == '/') { - outOffset = lastNonWsOffset; - return true; - } - if (!isInLineComment && nextChar == '*') { - outOffset = lastNonWsOffset; - return true; - } - } - break; - case '\\': - if (isInChar || (isInString && !isVerbatimString)) - pos++; - break; - case '@': - if (!(isInString || isInChar || isInLineComment || isInBlockComment) && pos + 1 < max && data.Document.GetCharAt (pos + 1) == '"') { - isInString = true; - isVerbatimString = true; - pos++; - } - break; - case '"': - if (!(isInChar || isInLineComment || isInBlockComment)) { - if (isInString && isVerbatimString && pos + 1 < max && data.Document.GetCharAt (pos + 1) == '"') { - pos++; - } else { - isInString = !isInString; - isVerbatimString = false; - } - } - break; - case '\'': - if (!(isInString || isInLineComment || isInBlockComment)) - isInChar = !isInChar; - break; + var offset = curLine.Offset; + string lineText = data.GetTextAt (caretOffset, max - caretOffset); + var lexer = new CSharpCompletionEngineBase.MiniLexer (lineText); + lexer.Parse ((ch, i) => { + if (lexer.IsInSingleComment || lexer.IsInMultiLineComment) + return true; + if (ch == '}' && lexer.IsFistNonWs && !IsSemicolonalreadyPlaced (data, caretOffset)) { + lastNonWsChar = ';'; + return true; } if (!char.IsWhiteSpace (ch)) { - firstChar = false; - lastNonWsOffset = pos; + lastNonWsOffset = caretOffset + i; lastNonWsChar = ch; } - } + return false; + }); // if the line ends with ';' the line end is not the correct place for a new semicolon. if (lastNonWsChar == ';') return false; diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/CSharpSyntaxMode.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/CSharpSyntaxMode.cs index 998368be6a..76fa3cf026 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/CSharpSyntaxMode.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/CSharpSyntaxMode.cs @@ -281,6 +281,54 @@ namespace MonoDevelop.CSharp.Highlighting } tree.AddStyle (startOffset, endOffset, color); } + + public override void VisitSimpleType (SimpleType simpleType) + { + var identifierToken = simpleType.IdentifierToken; + VisitChildrenUntil(simpleType, identifierToken); + var resolveResult = resolver.Resolve (simpleType, cancellationToken); + if (resolveResult.Type.Namespace == "System") { + switch (resolveResult.Type.Name) { + case "nfloat": + case "nint": + case "nuint": + Colorize(identifierToken, "Keyword(Type)"); + break; + default: + Colorize (identifierToken, resolveResult); + break; + } + } else { + Colorize (identifierToken, resolveResult); + } + VisitChildrenAfter(simpleType, identifierToken); + } + + public override void VisitIdentifierExpression (IdentifierExpression identifierExpression) + { + var identifier = identifierExpression.IdentifierToken; + VisitChildrenUntil(identifierExpression, identifier); + if (isInAccessorContainingValueParameter && identifierExpression.Identifier == "value") { + Colorize(identifier, valueKeywordColor); + } else { + var resolveResult = resolver.Resolve (identifierExpression, cancellationToken); + if (resolveResult.Type.Namespace == "System") { + switch (resolveResult.Type.Name) { + case "nfloat": + case "nint": + case "nuint": + Colorize(identifier, "Keyword(Type)"); + break; + default: + Colorize (identifier, resolveResult); + break; + } + } else { + Colorize (identifier, resolveResult); + } + } + VisitChildrenAfter(identifierExpression, identifier); + } } class QuickTaskVisitor : DepthFirstAstVisitor diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Parser/TypeSystemProvider.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Parser/TypeSystemProvider.cs index 475fac0ee1..0192f4a3e7 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Parser/TypeSystemProvider.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Parser/TypeSystemProvider.cs @@ -84,7 +84,13 @@ namespace MonoDevelop.CSharp.Parser result.ParsedFile = pf; result.Add (GetSemanticTags (unit)); - result.CreateRefactoringContext = (doc, token) => MDRefactoringContext.Create (doc, doc.Editor.Caret.Location, token).Result; + result.CreateRefactoringContext = delegate (MonoDevelop.Ide.Gui.Document doc, System.Threading.CancellationToken token) { + var task = MDRefactoringContext.Create (doc, doc.Editor.Caret.Location, token); + task.Wait (5000, token); + if (!task.IsCompleted) + return null; + return task.Result; + }; result.CreateRefactoringContextWithEditor = (data, resolver, token) => new MDRefactoringContext ((DotNetProject)project, data, result, (CSharpAstResolver)resolver, TextLocation.Empty, token); if (storeAst) { diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpCompilerParameters.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpCompilerParameters.cs index 6c528ba8f4..0f0ca7f675 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpCompilerParameters.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpCompilerParameters.cs @@ -33,6 +33,7 @@ using MonoDevelop.Core.Serialization; using MonoDevelop.Core; using Mono.Collections.Generic; using System.Linq; +using MonoDevelop.Projects.Formats.MSBuild; namespace MonoDevelop.CSharp.Project { @@ -48,7 +49,7 @@ namespace MonoDevelop.CSharp.Project /// <summary> /// This class handles project specific compiler parameters /// </summary> - public class CSharpCompilerParameters: DotNetConfigurationParameters + public class CSharpCompilerParameters: DotNetCompilerParameters { // Configuration parameters @@ -91,60 +92,26 @@ namespace MonoDevelop.CSharp.Project [ItemProperty("DebugType", DefaultValue="")] string debugType = ""; - #region Members required for backwards compatibility. Not used for anything else. - - [ItemProperty ("StartupObject", DefaultValue = null)] - internal string mainclass; - - [ProjectPathItemProperty ("ApplicationIcon", DefaultValue = null)] - internal string win32Icon; - - [ProjectPathItemProperty ("Win32Resource", DefaultValue = null)] - internal string win32Resource; - - [ItemProperty ("CodePage", DefaultValue = null)] - internal string codePage; + protected override void Write (IMSBuildPropertySet pset, MSBuildFileFormat format) + { + base.Write (pset, format); + pset.SetPropertyOrder ("DebugSymbols", "DebugType", "Optimize", "OutputPath", "DefineConstants", "ErrorReport", "WarningLevel", "TreatWarningsAsErrors", "DocumentationFile"); + pset.WriteObjectProperties (this, typeof(CSharpCompilerParameters)); + } - [ItemProperty ("GenerateDocumentation", DefaultValue = null)] - bool? generateXmlDocumentation = null; - - #endregion - - - protected override void OnEndLoad () + protected override void Read (IMSBuildPropertySet pset, MSBuildFileFormat format) { - base.OnEndLoad (); - - // Backwards compatibility. Move parameters to the project parameters object - if (ParentConfiguration != null && ParentConfiguration.ProjectParameters != null) { - CSharpProjectParameters cparams = (CSharpProjectParameters) ParentConfiguration.ProjectParameters; - if (win32Icon != null) { - cparams.Win32Icon = win32Icon; - win32Icon = null; - } - if (win32Resource != null) { - cparams.Win32Resource = win32Resource; - win32Resource = null; - } - if (mainclass != null) { - cparams.MainClass = mainclass; - mainclass = null; - } - if (!string.IsNullOrEmpty (codePage)) { - cparams.CodePage = int.Parse (codePage); - codePage = null; - } - } + base.Read (pset, format); + pset.ReadObjectProperties (this, typeof(CSharpCompilerParameters)); - if (generateXmlDocumentation.HasValue && ParentConfiguration != null) { - if (generateXmlDocumentation.Value) + var prop = pset.GetProperty ("GenerateDocumentation"); + if (prop != null && documentationFile != null) { + if (prop.GetValue<bool> ()) documentationFile = ParentConfiguration.CompiledOutputName.ChangeExtension (".xml"); else documentationFile = null; - generateXmlDocumentation = null; } } - public LangVersion LangVersion { get { diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpProjectExtension.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpProjectExtension.cs new file mode 100644 index 0000000000..5c66cf0c2d --- /dev/null +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpProjectExtension.cs @@ -0,0 +1,149 @@ +// +// CSharpProjectExtension.cs +// +// Author: +// Lluis Sanchez Gual <lluis@xamarin.com> +// +// Copyright (c) 2014 Xamarin, Inc (http://www.xamarin.com) +// +// 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 MonoDevelop.Projects; +using MonoDevelop.Projects.Formats.MSBuild; +using MonoDevelop.Core; +using MonoDevelop.Core.Serialization; +using MonoDevelop.Projects.Extensions; +using System.Collections.Generic; + +namespace MonoDevelop.CSharp.Project +{ + class CSharpProject: DotNetProject, ICSharpProject + { + [ItemProperty ("StartupObject", DefaultValue = "")] + string mainclass = string.Empty; + + [ProjectPathItemProperty ("ApplicationIcon", DefaultValue = "")] + string win32Icon = String.Empty; + + [ProjectPathItemProperty ("Win32Resource", DefaultValue = "")] + string win32Resource = String.Empty; + + [ItemProperty ("CodePage", DefaultValue = 0)] + int codePage; + + static CSharpResourceIdBuilder resourceHandler = new CSharpResourceIdBuilder (); + + public CSharpProject () + { + Initialize (this); + DefaultImports.Add ("$(MSBuildBinPath)\\Microsoft.CSharp.targets"); + } + + public string MainClass { + get { + return mainclass; + } + set { + mainclass = value ?? string.Empty; + } + } + + public int CodePage { + get { + return codePage; + } + set { + codePage = value; + } + } + + public string Win32Icon { + get { + return win32Icon; + } + set { + win32Icon = value ?? string.Empty; + } + } + + public string Win32Resource { + get { + return win32Resource; + } + set { + win32Resource = value ?? string.Empty; + } + } + + protected override object OnGetService (Type t) + { + if (t == typeof(IResourceHandler)) + return resourceHandler; + return base.GetService (t); + } + + protected override void OnWriteProject (ProgressMonitor monitor, MSBuildProject msproject) + { + base.OnWriteProject (monitor, msproject); + msproject.GetGlobalPropertyGroup ().WriteObjectProperties (this, typeof(CSharpProject)); + } + + protected override void OnReadProject (ProgressMonitor monitor, MSBuildProject msproject) + { + base.OnReadProject (monitor, msproject); + msproject.GetGlobalPropertyGroup ().ReadObjectProperties (this, typeof(CSharpProject)); + } + + protected override void OnReadConfiguration (ProgressMonitor monitor, ProjectConfiguration config, IMSBuildPropertySet pset) + { + base.OnReadConfiguration (monitor, config, pset); + + // Backwards compatibility. Move parameters to the project parameters object + + var prop = pset.GetProperty ("ApplicationIcon"); + if (prop != null) + win32Icon = prop.GetPathValue (); + + prop = pset.GetProperty ("Win32Resource"); + if (prop != null) + win32Resource = prop.GetPathValue (); + + prop = pset.GetProperty ("StartupObject"); + if (prop != null) + mainclass = prop.Value; + + prop = pset.GetProperty ("CodePage"); + if (prop != null) + codePage = int.Parse (prop.Value); + } + } + + public interface ICSharpProject + { + string MainClass { get; set; } + + int CodePage { get; set; } + + string Win32Icon { get; set; } + + string Win32Resource { get; set; } + } + +} + diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CompilerOptionsPanelWidget.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CompilerOptionsPanelWidget.cs index 21300b94a3..465f0e95f2 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CompilerOptionsPanelWidget.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CompilerOptionsPanelWidget.cs @@ -53,7 +53,7 @@ namespace MonoDevelop.CSharp.Project this.project = project; DotNetProjectConfiguration configuration = (DotNetProjectConfiguration) project.GetConfiguration (IdeApp.Workspace.ActiveConfiguration); CSharpCompilerParameters compilerParameters = (CSharpCompilerParameters) configuration.CompilationParameters; - CSharpProjectParameters projectParameters = (CSharpProjectParameters) configuration.ProjectParameters; + var csproject = (CSharpProject)project; ListStore store = new ListStore (typeof (string));
store.AppendValues (GettextCatalog.GetString ("Executable"));
@@ -75,7 +75,7 @@ namespace MonoDevelop.CSharp.Project classListStore = new ListStore (typeof(string));
mainClassEntry.Model = classListStore;
mainClassEntry.TextColumn = 0;
- ((Entry)mainClassEntry.Child).Text = projectParameters.MainClass ?? string.Empty; + ((Entry)mainClassEntry.Child).Text = csproject.MainClass ?? string.Empty; UpdateTarget (); } @@ -85,16 +85,16 @@ namespace MonoDevelop.CSharp.Project foreach (TextEncoding e in TextEncoding.SupportedEncodings) { if (e.CodePage == -1) continue; - if (e.CodePage == projectParameters.CodePage) + if (e.CodePage == csproject.CodePage) foundEncoding = e.Id; codepageEntry.AppendText (e.Id); } if (foundEncoding != null) codepageEntry.Entry.Text = foundEncoding; - else if (projectParameters.CodePage != 0) - codepageEntry.Entry.Text = projectParameters.CodePage.ToString (); + else if (csproject.CodePage != 0) + codepageEntry.Entry.Text = csproject.CodePage.ToString (); - iconEntry.Path = projectParameters.Win32Icon; + iconEntry.Path = csproject.Win32Icon; iconEntry.DefaultPath = project.BaseDirectory; allowUnsafeCodeCheckButton.Active = compilerParameters.UnsafeCode; noStdLibCheckButton.Active = compilerParameters.NoStdLib; @@ -171,15 +171,15 @@ namespace MonoDevelop.CSharp.Project project.CompileTarget = compileTarget; - CSharpProjectParameters projectParameters = (CSharpProjectParameters) project.LanguageParameters; + var csproject = (CSharpProject)project; - projectParameters.CodePage = codePage; + csproject.CodePage = codePage; if (iconEntry.Sensitive) - projectParameters.Win32Icon = iconEntry.Path; + csproject.Win32Icon = iconEntry.Path; if (mainClassEntry.Sensitive) - projectParameters.MainClass = mainClassEntry.Entry.Text; + csproject.MainClass = mainClassEntry.Entry.Text; foreach (DotNetProjectConfiguration configuration in configs) { CSharpCompilerParameters compilerParameters = (CSharpCompilerParameters) configuration.CompilationParameters; diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpProjectParameters.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/PortableCSharpProjectFlavor.cs index 7e010c0de6..c7d50c2884 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpProjectParameters.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/PortableCSharpProjectFlavor.cs @@ -1,21 +1,21 @@ -// -// ProjectParameters.cs -// +// +// PortableCSharpProjectFlavor.cs +// // Author: -// Lluis Sanchez Gual <lluis@novell.com> -// -// Copyright (c) 2009 Novell, Inc (http://www.novell.com) -// +// Lluis Sanchez Gual <lluis@xamarin.com> +// +// Copyright (c) 2014 Xamarin, Inc (http://www.xamarin.com) +// // 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 @@ -23,62 +23,27 @@ // 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 MonoDevelop.Core.Serialization; using MonoDevelop.Projects; +using MonoDevelop.Core; +using MonoDevelop.Projects.Formats.MSBuild; namespace MonoDevelop.CSharp.Project { - public class CSharpProjectParameters: ProjectParameters + public class PortableCSharpProjectFlavor: PortableDotNetProjectFlavor { - [ItemProperty ("StartupObject", DefaultValue = "")] - string mainclass = string.Empty; - - [ProjectPathItemProperty ("ApplicationIcon", DefaultValue = "")] - string win32Icon = String.Empty; - - [ProjectPathItemProperty ("Win32Resource", DefaultValue = "")] - string win32Resource = String.Empty; - - [ItemProperty ("CodePage", DefaultValue = 0)] - int codePage; - - public string MainClass { - get { - return mainclass; - } - set { - mainclass = value ?? string.Empty; - } - } - - public int CodePage { - get { - return codePage; - } - set { - codePage = value; - } + protected override void Initialize () + { + base.Initialize (); + Project.UseMSBuildEngine = true; } - - public string Win32Icon { - get { - return win32Icon; - } - set { - win32Icon = value ?? string.Empty; - } - } - - public string Win32Resource { - get { - return win32Resource; - } - set { - win32Resource = value ?? string.Empty; - } + + protected override void OnWriteProject (ProgressMonitor monitor, MSBuildProject msproject) + { + base.OnWriteProject (monitor, msproject); + msproject.RemoveImport ("$(MSBuildBinPath)\\Microsoft.CSharp.targets"); + msproject.AddNewImport ("$(MSBuildExtensionsPath32)\\Microsoft\\Portable\\$(TargetFrameworkVersion)\\Microsoft.Portable.CSharp.targets"); } - } } + diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/Actions/MoveTypeToFile.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/Actions/MoveTypeToFile.cs index bf1523421d..d9d8be69ac 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/Actions/MoveTypeToFile.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/Actions/MoveTypeToFile.cs @@ -72,7 +72,7 @@ namespace MonoDevelop.CSharp.Refactoring.CodeActions if (IsSingleType (ctx)) { FileService.RenameFile (ctx.TextEditor.FileName, correctFileName); if (ctx.FileContainerProject != null) - ctx.FileContainerProject.Save (new NullProgressMonitor ()); + ctx.FileContainerProject.Save (new ProgressMonitor ()); return; } @@ -103,7 +103,7 @@ namespace MonoDevelop.CSharp.Refactoring.CodeActions File.WriteAllText (correctFileName, content); context.FileContainerProject.AddFile (correctFileName); - MonoDevelop.Ide.IdeApp.ProjectOperations.Save (context.FileContainerProject); + MonoDevelop.Ide.IdeApp.ProjectOperations.SaveAsync (context.FileContainerProject); } static bool IsBlankLine (TextDocument doc, int i) diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/MDRefactoringContext.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/MDRefactoringContext.cs index a831bc4171..8674904f33 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/MDRefactoringContext.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/MDRefactoringContext.cs @@ -235,7 +235,7 @@ namespace MonoDevelop.CSharp.Refactoring.CodeActions if (sharedResolver == null) return null; return new MDRefactoringContext (document, sharedResolver, loc, cancellationToken); - }, TaskContinuationOptions.ExecuteSynchronously); + }); } internal MDRefactoringContext (Document document, CSharpAstResolver resolver, TextLocation loc, CancellationToken cancellationToken = default (CancellationToken)) : base (resolver, cancellationToken) diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/MDRefactoringScript.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/MDRefactoringScript.cs index 80db3eb8a1..02e35f0e04 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/MDRefactoringScript.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring.CodeActions/MDRefactoringScript.cs @@ -269,7 +269,11 @@ namespace MonoDevelop.CSharp.Refactoring.CodeActions if (operationsRunning-- == 0) { isDisposed = true; undoGroup.Dispose (); - base.Dispose (); + try { + base.Dispose (); + } catch (Exception e) { + LoggingService.LogError ("Error while disposing refactoring script", e); + } } foreach (var script in startedScripts) script.Dispose (); @@ -363,7 +367,7 @@ namespace MonoDevelop.CSharp.Refactoring.CodeActions if (project != null) { project.AddFile (correctFileName); - IdeApp.ProjectOperations.Save (project); + IdeApp.ProjectOperations.SaveAsync (project); } IdeApp.Workbench.OpenDocument (correctFileName, project); } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpReferenceFinder.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpReferenceFinder.cs index 950209fcbf..e8e1278ee1 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpReferenceFinder.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpReferenceFinder.cs @@ -285,7 +285,7 @@ namespace MonoDevelop.CSharp.Refactoring return result; } - public override IEnumerable<MemberReference> FindReferences (Project project, IProjectContent content, IEnumerable<FilePath> possibleFiles, IProgressMonitor monitor, IEnumerable<object> members) + public override IEnumerable<MemberReference> FindReferences (Project project, IProjectContent content, IEnumerable<FilePath> possibleFiles, ProgressMonitor monitor, IEnumerable<object> members) { if (content == null) throw new ArgumentNullException ("content", "Project content not set."); diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpBindingCompilerManager.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpBindingCompilerManager.cs index 363af546b5..c850fda17b 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpBindingCompilerManager.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpBindingCompilerManager.cs @@ -55,10 +55,10 @@ namespace MonoDevelop.CSharp sb.AppendLine (); } - public static BuildResult Compile (ProjectItemCollection projectItems, DotNetProjectConfiguration configuration, ConfigurationSelector configSelector, IProgressMonitor monitor) + public static BuildResult Compile (ProjectItemCollection projectItems, DotNetProjectConfiguration configuration, ConfigurationSelector configSelector, ProgressMonitor monitor) { var compilerParameters = (CSharpCompilerParameters)configuration.CompilationParameters ?? new CSharpCompilerParameters (); - var projectParameters = (CSharpProjectParameters)configuration.ProjectParameters ?? new CSharpProjectParameters (); + var projectParameters = (CSharpProject) configuration.ParentItem; FilePath outputName = configuration.CompiledOutputName; string responseFileName = Path.GetTempFileName (); @@ -418,7 +418,7 @@ namespace MonoDevelop.CSharp return result; } - static int DoCompilation (IProgressMonitor monitor, string compilerName, string compilerArgs, string working_dir, ExecutionEnvironment envVars, List<string> gacRoots, ref string output, ref string error) + static int DoCompilation (ProgressMonitor monitor, string compilerName, string compilerArgs, string working_dir, ExecutionEnvironment envVars, List<string> gacRoots, ref string output, ref string error) { output = Path.GetTempFileName (); error = Path.GetTempFileName (); @@ -448,9 +448,9 @@ namespace MonoDevelop.CSharp pinfo.RedirectStandardOutput = true; pinfo.RedirectStandardError = true; - MonoDevelop.Core.Execution.ProcessWrapper pw = Runtime.ProcessService.StartProcess (pinfo, outwr, errwr, null); - using (var mon = new AggregatedOperationMonitor (monitor, pw)) { - pw.WaitForOutput (); + ProcessWrapper pw = Runtime.ProcessService.StartProcess (pinfo, outwr, errwr, null); + using (monitor.CancellationToken.Register (pw.Cancel)) { + pw.Task.Wait (); } int exitCode = pw.ExitCode; bool cancelRequested = pw.CancelRequested;
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpLanguageBinding.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpLanguageBinding.cs index 968bb4af36..eab17d4f76 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpLanguageBinding.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpLanguageBinding.cs @@ -72,12 +72,12 @@ namespace MonoDevelop.CSharp return StringComparer.OrdinalIgnoreCase.Equals (Path.GetExtension (fileName), ".cs"); } - public BuildResult Compile (ProjectItemCollection projectItems, DotNetProjectConfiguration configuration, ConfigurationSelector configSelector, IProgressMonitor monitor) + public BuildResult Compile (ProjectItemCollection projectItems, DotNetProjectConfiguration configuration, ConfigurationSelector configSelector, ProgressMonitor monitor) { return CSharpBindingCompilerManager.Compile (projectItems, configuration, configSelector, monitor); } - public ConfigurationParameters CreateCompilationParameters (XmlElement projectOptions) + public DotNetCompilerParameters CreateCompilationParameters (XmlElement projectOptions) { CSharpCompilerParameters pars = new CSharpCompilerParameters (); if (projectOptions != null) { @@ -96,11 +96,6 @@ namespace MonoDevelop.CSharp return pars; } - public ProjectParameters CreateProjectParameters (XmlElement projectOptions) - { - return new CSharpProjectParameters (); - } - public string SingleLineCommentTag { get { return "//"; } } public string BlockCommentStartTag { get { return "/*"; } } public string BlockCommentEndTag { get { return "*/"; } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs index 7739ce1084..4484afcad9 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs @@ -46,6 +46,8 @@ namespace MonoDevelop.CSharp { IdeApp.Workspace.FileAddedToProject -= HandleProjectChanged; IdeApp.Workspace.FileRemovedFromProject -= HandleProjectChanged; + IdeApp.Workspace.WorkspaceItemUnloaded -= HandleWorkspaceItemUnloaded; + IdeApp.Workspace.WorkspaceItemLoaded -= HandleWorkspaceItemLoaded;; if (caret != null) { caret.PositionChanged -= UpdatePath; @@ -65,20 +67,46 @@ namespace MonoDevelop.CSharp Mono.TextEditor.Caret caret; CSharpCompletionTextEditorExtension ext; - List<DotNetProject> ownerProjects; + List<DotNetProject> ownerProjects = new List<DotNetProject> (); public override void Initialize () { CurrentPath = new PathEntry[] { new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = null } }; isPathSet = false; - UpdateOwnerProjects (); - UpdatePath (null, null); + // Delay the execution of UpdateOwnerProjects since it may end calling Document.AttachToProject, + // which shouldn't be called while the extension chain is being initialized. + Gtk.Application.Invoke (delegate { + UpdateOwnerProjects (); + UpdatePath (null, null); + }); caret = Document.Editor.Caret; caret.PositionChanged += UpdatePath; ext = Document.GetContent<CSharpCompletionTextEditorExtension> (); ext.TypeSegmentTreeUpdated += HandleTypeSegmentTreeUpdated; IdeApp.Workspace.FileAddedToProject += HandleProjectChanged; IdeApp.Workspace.FileRemovedFromProject += HandleProjectChanged; + IdeApp.Workspace.WorkspaceItemUnloaded += HandleWorkspaceItemUnloaded; + IdeApp.Workspace.WorkspaceItemLoaded += HandleWorkspaceItemLoaded;; + } + + void HandleWorkspaceItemLoaded (object sender, WorkspaceItemEventArgs e) + { + if (ownerProjects != null) + return; + UpdateOwnerProjects (e.Item.GetAllItems<DotNetProject> ()); + } + + void HandleWorkspaceItemUnloaded (object sender, WorkspaceItemEventArgs e) + { + if (ownerProjects == null) + return; + foreach (var p in e.Item.GetAllItems<DotNetProject> ()) { + ownerProjects.Remove (p); + } + if (ownerProjects.Count == 0) { + ownerProjects = null; + Document.AttachToProject (null); + } } void HandleProjectChanged (object sender, ProjectFileEventArgs e) @@ -92,9 +120,9 @@ namespace MonoDevelop.CSharp UpdatePath (null, null); } - void UpdateOwnerProjects () + void UpdateOwnerProjects (IEnumerable<DotNetProject> allProjects) { - var projects = new HashSet<DotNetProject> (IdeApp.Workspace.GetAllSolutionItems<DotNetProject> ().Where (p => p.IsFileInProject (Document.FileName))); + var projects = new HashSet<DotNetProject> (allProjects.Where (p => p.IsFileInProject (Document.FileName))); if (ownerProjects == null || !projects.SetEquals (ownerProjects)) { ownerProjects = projects.OrderBy (p => p.Name).ToList (); var dnp = Document.Project as DotNetProject; @@ -106,6 +134,11 @@ namespace MonoDevelop.CSharp Document.AttachToProject (pp); } } + } + + void UpdateOwnerProjects () + { + UpdateOwnerProjects (IdeApp.Workspace.GetAllItems<DotNetProject> ()); if (Document.Project == null && ownerProjects.Count > 0) Document.AttachToProject (ownerProjects[0]); } @@ -481,7 +514,7 @@ namespace MonoDevelop.CSharp var curType = (EntityDeclaration)unit.GetNodeAt (loc, n => n is TypeDeclaration || n is DelegateDeclaration); - var curProject = ownerProjects.Count > 1 ? Document.Project : null; + var curProject = ownerProjects != null && ownerProjects.Count > 1 ? Document.Project : null; var segMember = compExt.GetMemberAt (caretOffset); if (segMember != null) { @@ -512,7 +545,7 @@ namespace MonoDevelop.CSharp var result = new List<PathEntry> (); - if (ownerProjects.Count > 1) { + if (ownerProjects != null && ownerProjects.Count > 1) { // Current project if there is more than one result.Add (new PathEntry (ImageService.GetIcon (Document.Project.StockIcon, Gtk.IconSize.Menu), GLib.Markup.EscapeText (Document.Project.Name)) { Tag = Document.Project }); } diff --git a/main/src/addins/CSharpBinding/gtk-gui/gui.stetic b/main/src/addins/CSharpBinding/gtk-gui/gui.stetic index ea86d2e379..ebc8427558 100644 --- a/main/src/addins/CSharpBinding/gtk-gui/gui.stetic +++ b/main/src/addins/CSharpBinding/gtk-gui/gui.stetic @@ -514,6 +514,7 @@ None</property> </widget> <widget class="Gtk.Bin" id="MonoDevelop.CSharp.Project.CompilerOptionsPanelWidget" design-size="471 438"> <property name="MemberName" /> + <property name="GeneratePublic">False</property> <child> <widget class="Gtk.VBox" id="vbox1"> <property name="MemberName" /> diff --git a/main/src/addins/CSharpBinding/templates/PortableLibrary.xpt.xml b/main/src/addins/CSharpBinding/templates/PortableLibrary.xpt.xml index 51a5345be6..a26a237dce 100644 --- a/main/src/addins/CSharpBinding/templates/PortableLibrary.xpt.xml +++ b/main/src/addins/CSharpBinding/templates/PortableLibrary.xpt.xml @@ -24,8 +24,8 @@ <StartupProject>${ProjectName}</StartupProject> </Options> - <Project name = "${ProjectName}" directory = "." type = "PortableDotNet"> - <Options Target = "Library" TargetFrameworkVersion = ".NETPortable,Version=v4.5,Profile=Profile78"/> + <Project name = "${ProjectName}" directory = "."> + <Options Target = "Library" TargetFrameworkVersion = ".NETPortable,Version=v4.5,Profile=Profile78" flavorIds="{786C830F-07A1-408B-BD7F-6EE04809D6DB}"/> <References> </References> <Files> |