From 3d45a3bcce2c3d85ab38831803d841ccee66dd8e Mon Sep 17 00:00:00 2001 From: bettinaheim <34236215+bettinaheim@users.noreply.github.com> Date: Sat, 17 Aug 2019 09:02:22 -0700 Subject: [PATCH] Code Actions for deprecated NOT, AND, and OR (#72) (#119) --- .../CompilationManager/DiagnosticTools.cs | 2 +- .../EditorSupport/CodeActions.cs | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/QsCompiler/CompilationManager/DiagnosticTools.cs b/src/QsCompiler/CompilationManager/DiagnosticTools.cs index f8158de6b9..9e3fd235a9 100644 --- a/src/QsCompiler/CompilationManager/DiagnosticTools.cs +++ b/src/QsCompiler/CompilationManager/DiagnosticTools.cs @@ -202,7 +202,7 @@ internal static Func ErrorType(params ErrorCode[] types) /// internal static Func WarningType(params WarningCode[] types) { - var codes = types.Select(err => err.Code()); + var codes = types.Select(war => war.Code()); return m => m.Severity == DiagnosticSeverity.Warning && codes.Contains(m.Code); } diff --git a/src/QsCompiler/CompilationManager/EditorSupport/CodeActions.cs b/src/QsCompiler/CompilationManager/EditorSupport/CodeActions.cs index 29046c344d..8ffa4fd24d 100644 --- a/src/QsCompiler/CompilationManager/EditorSupport/CodeActions.cs +++ b/src/QsCompiler/CompilationManager/EditorSupport/CodeActions.cs @@ -144,18 +144,21 @@ private static IEnumerable> NamespaceSuggestionsForTypeAtPos { if (file == null || diagnostics == null) return Enumerable.Empty<(string, WorkspaceEdit)>(); var deprecatedUnitTypes = diagnostics.Where(DiagnosticTools.WarningType(WarningCode.DeprecatedUnitType)); - if (!deprecatedUnitTypes.Any()) return Enumerable.Empty<(string, WorkspaceEdit)>(); + var deprecatedNOToperators = diagnostics.Where(DiagnosticTools.WarningType(WarningCode.DeprecatedNOToperator)); + var deprecatedANDoperators = diagnostics.Where(DiagnosticTools.WarningType(WarningCode.DeprecatedANDoperator)); + var deprecatedORoperators = diagnostics.Where(DiagnosticTools.WarningType(WarningCode.DeprecatedORoperator)); - // Suggestion for replacing deprecated unit types - (string, WorkspaceEdit) EditAtPosition(string text, Position start, Position end) + (string, WorkspaceEdit) ReplaceWith(string text, Range range) { - var edit = new TextEdit { Range = new Range { Start = start, End = end }, NewText = text }; - return ("Replace with \"" + $"{text}" + "\"", file.GetWorkspaceEdit(edit)); + var edit = new TextEdit { Range = range.Copy(), NewText = text }; + return ($"Replace with \"{text.Trim()}\".", file.GetWorkspaceEdit(edit)); } - var suggestionsForUnitType = deprecatedUnitTypes - .Select(d => EditAtPosition(Keywords.qsUnit.id, d.Range.Start, d.Range.End)); - return suggestionsForUnitType; + var suggestionsForUnitType = deprecatedUnitTypes.Select(d => ReplaceWith(Keywords.qsUnit.id, d.Range)); + var suggestionsForNOT = deprecatedNOToperators.Select(d => ReplaceWith(Keywords.qsNOTop.op + " ", d.Range)); + var suggestionsForAND = deprecatedANDoperators.Select(d => ReplaceWith(Keywords.qsANDop.op, d.Range)); + var suggestionsForOR = deprecatedORoperators.Select(d => ReplaceWith(Keywords.qsORop.op, d.Range)); + return suggestionsForUnitType.Concat(suggestionsForNOT).Concat(suggestionsForAND).Concat(suggestionsForOR); } } } \ No newline at end of file