mirror of
https://github.com/sbroenne/mcp-server-excel.git
synced 2026-09-19 07:53:08 +08:00
29adbb3b25
* refactor: eliminate cargo cult patterns in PivotTable and Range commands - Create PivotTableHelpers class with centralized OLAP detection: - IsOlapPivotTable() - boolean check with COM cleanup - TryGetCubeFields() - returns cubeFields for subsequent operations - Replace duplicated OLAP detection try-catch blocks across 8 files: - PivotTableCommands.Fields.cs - PivotTableCommands.Lifecycle.cs - PivotTableCommands.cs - PivotTableCommands.CalculatedMembers.cs - PivotTableCommands.CalculatedFields.cs - OlapPivotTableFieldStrategy.cs - RegularPivotTableFieldStrategy.cs - PivotTableFieldStrategyFactory.cs - Fix nullable bool comparisons (== true -> is true): - RangeCommands.Validation.cs - OlapPivotTableFieldStrategy.cs (3 instances) - PowerQueryCommands.Helpers.cs Fixes #333 * refactor: eliminate PivotTable strategy execution boilerplate - Create ExecuteWithStrategy<TResult> helper method centralizing: - PivotTable lookup via CoreLookupHelpers.FindPivotTable - Strategy creation via PivotTableFieldStrategyFactory - Operation execution with proper COM cleanup in finally block - Refactor 12 methods to use helper (expression-bodied): - Fields: AddRowField, AddColumnField, AddValueField, AddFilterField, RemoveField, SetFieldFunction, SetFieldName - Grouping: GroupByDate, GroupByNumeric - Layout: SetLayout, Subtotals: SetSubtotals, GrandTotals: SetGrandTotals - CalculatedFields: CreateCalculatedField - Analysis: SetFieldFilter, SortField - Remove unused 'using Sbroenne.ExcelMcp.ComInterop' from 4 files - Remove redundant null check in SetGrandTotals (FindPivotTable throws) Methods kept as-is (require context access or complex logic): - SetFieldFormat (needs ctx.FormatTranslator) - ListFields, GetData (complex iteration/extraction logic) - ListCalculatedFields, DeleteCalculatedField (OLAP-specific paths) Reduction: ~150 lines of duplicate boilerplate eliminated * refactor: eliminate redundant table null checks - Change TableCommands.FindTable to call CoreLookupHelpers.FindTable (which throws) instead of TryFindTable (which returns null) - Remove 22 redundant null checks across 9 TableCommands files: - Data.cs (2), Filters.cs (4), Lifecycle.cs (3) - NumberFormat.cs (2), Sort.cs (2), Structure.cs (4) - StructuredReferences.cs (1), Columns.cs (3), DataModel.cs (1) - Same pattern fix as PivotTable strategy execution: FindTable now throws, so callers don't need to check+throw Reduction: 88 lines of redundant null check boilerplate eliminated * refactor: remove dead aggregation helpers and consolidate VBA type mapping - Remove 3 unused methods from PivotTableCommands.cs (IsValidAggregationForDataType, GetValidAggregationsForDataType, GetComAggregationFunction) - Remove 1 unused method from OlapPivotTableFieldStrategy.cs (GetComAggregationFunction) - Add GetVbaModuleTypeName() helper to VbaCommands.cs - Replace 2 inline switch expressions with helper in VbaCommands.Lifecycle.cs Net reduction: 71 lines (17+/88-) * refactor: consolidate GetAreaName into PivotTableHelpers - Add GetAreaName() to PivotTableHelpers.cs as shared utility - Remove duplicated GetAreaName() from PivotTableCommands.cs (dead code) - Remove duplicated GetAreaName() from OlapPivotTableFieldStrategy.cs - Remove duplicated GetAreaName() from RegularPivotTableFieldStrategy.cs - Update all 8 usages to use PivotTableHelpers.GetAreaName() Net reduction: 27 lines (26+/53-) * refactor: consolidate GetAggregationFunctionFromCom into PivotTableHelpers * refactor: consolidate DetectFieldDataType into PivotTableHelpers - Move DetectFieldDataType from PivotTableCommands and RegularPivotTableFieldStrategy to PivotTableHelpers - Update 8 usages across 4 files to use centralized helper - Eliminates ~50 lines of duplicated data type detection logic * refactor: consolidate GetFieldUniqueValues into PivotTableHelpers - Add GetFieldUniqueValues to PivotTableHelpers (identical logic) - Remove dead code from PivotTableCommands.cs (method was defined but never called) - Remove duplicate from RegularPivotTableFieldStrategy.cs - Update 3 callers to use centralized helper - Eliminates ~40 lines of duplicated/dead code * refactor: consolidate ParseColor and ParseBorderStyle into FormattingHelpers * refactor: remove dead WithSessionAsync method * refactor: remove dead code (-937 lines) Removed unused code across all layers: Core: - IsValidTableName (TableCommands.cs) - never called - CreatePowerQueryPipeline, PowerQueryConfig, POWER_QUERY_DATA_MODEL_ERROR (ResiliencePipelines.cs) - RemoveQueryTablesFromSheet, CreateQueryTable (PowerQueryHelpers.cs) - RemoveQueryConnections, CreateQueryTableConnection, SetQueryLoadToDataModel, CheckQueryDataModelConfiguration (PowerQueryCommands.Helpers.cs) - GetConnectionNames, RemoveConnections (ConnectionHelpers.cs) - ExcelConstants.cs - entire file never referenced ComInterop: - SpinWaitDelayMs, XlExcel12Binary constants MCP Server: - style_names.md, powerquery_targetCellAddress.md - completion files never loaded - excel_datamodel.md - prompt content never wired up (info already in tool description) Tests: - CreateMultipleConnections (ConnectionTestHelper.cs) * refactor: remove dead completion handler infrastructure (-349 lines) Removed ExcelCompletionHandler.cs and supporting files which were written but never wired up to the MCP server (HandleCompletion never called). Deleted files: - ExcelCompletionHandler.cs (178 lines) - never registered with MCP - 7 completion markdown files (border_styles, border_weights, load_destination, privacy_level, table_styles, validation_operators, validation_types) Also cleaned up: - Removed LoadCompletion/LoadCompletionValues from MarkdownLoader.cs - Removed unused ListEmbeddedResources debugging method - Updated mcp-llm-guidance.instructions.md to reflect actual status * fix: suppress CA1031 warnings for intentional COM interop patterns --------- Co-authored-by: Stefan Broenner <stefan.broenner@microsoft.comm>