You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+63-13Lines changed: 63 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,43 +8,91 @@
8
8
9
9
> :information_source: This component is unofficial and unsupported by OutSystems.
10
10
11
-

⚡ _Screenshot showing the development of an ODC External Library in Visual Studio. The **ODC Custom Code Analyzer** flags several rule violations in the Problems panel. A related Quick Fix menu is open for one rule violation, offering to "Fix this type mapping" so the field correctly matches its `OSDataType.PhoneNumber`. You can get identical functionality in Visual Studio Code and Rider._ ⚡
12
14
13
15
## Overview
14
16
15
17
When you want to extend your ODC apps with custom C# code, you do so with the [External Libraries SDK](https://success.outsystems.com/documentation/outsystems_developer_cloud/building_apps/extend_your_apps_with_custom_code/external_libraries_sdk_readme/). This SDK allows you to write C# code that you can call from your ODC apps.
16
18
17
-
Although IntelliSense in your IDE guides the available SDK decorators and their syntax, it does not guide the rules you must follow (for example, on [naming](https://www.outsystems.com/tk/redirect?g=OS-ELG-MODL-05019) and [design decisions](https://www.outsystems.com/tk/redirect?g=OS-ELG-MODL-05018)). This guidance is provided when uploading your project's built assembly to the ODC Portal, where you get feedback on rule violations. **Using this component brings that feedback forward and gives you real-time feedback on compliance with the rules as you write the code. You also get real-time guidance on best practices.**
19
+
Although IntelliSense in your IDE guides the available SDK decorators and their syntax, it does not guide the rules you must follow (for example, on [naming](https://www.outsystems.com/tk/redirect?g=OS-ELG-MODL-05019) and [design decisions](https://www.outsystems.com/tk/redirect?g=OS-ELG-MODL-05018)). This guidance is provided when uploading your project's built assembly to the ODC Portal, where you get feedback on rule violations. **Using this component brings that feedback forward and gives you real-time feedback on compliance with the rules as you write the code. You also get real-time guidance on best practices and automatic fixes.**
18
20
19
21
### Technical Primer
20
22
21
23
When you upload your project's built assembly to the ODC Portal, it does not have access to the underlying code—the ODC Portal checks compliance with the rules by reflecting on the assembly's metadata.
22
24
23
25
This component, built from scratch, implements the rules using the rich code analysis APIs of [Roslyn](https://github.com/dotnet/roslyn), the .NET compiler.
The analyzer operates in two distinct phases, registered through the Roslyn `AnalysisContext`:
55
+
The analyzer operates in two distinct phases, registered through the Roslyn [`AnalysisContext`](https://github.com/jonathanalgar/CustomCode-Analyzer/blob/33c0d5ce0a762236a495ebc940b688e9e14cd901/src/CustomCode-Analyzer/Analyzer.cs#L355-L364):
28
56
29
-
1.**Symbol analysis phase** – Triggered by `RegisterSymbolAction`, this phase performs immediate syntax and semantic analysis on individual declarations as you type. For example, when you declare a method, the analyzer instantly checks if its name starts with an underscore and reports a violation if it does (`NameBeginsWithUnderscoresRule`). These diagnostics appear immediately in your IDE's Problems window.
57
+
1.**Symbol analysis phase**
58
+
Triggered by [`RegisterSymbolAction`](https://github.com/jonathanalgar/CustomCode-Analyzer/blob/33c0d5ce0a762236a495ebc940b688e9e14cd901/src/CustomCode-Analyzer/Analyzer.cs#L383-L410), this phase performs immediate syntax and semantic analysis on individual declarations as you type. For example, when you declare a method, the analyzer instantly checks if its name starts with an underscore and reports a violation if it does (`NameBeginsWithUnderscoreRule`). These diagnostics appear immediately in your IDE's Problems window.
30
59
31
-
2.**Compilation end phase** – Registered via `RegisterCompilationEndAction`, this phase runs after all symbols have been processed and the semantic model is complete. For example, it ensures exactly one `[OSInterface]` exists across your entire codebase by maintaining a `ConcurrentDictionary` of interface declarations and validating their uniqueness (`NoSingleInterfaceRule` or `ManyInterfacesRule`). These diagnostics may appear with a slight delay as they require complete semantic analysis.
60
+
2.**Compilation end phase**
61
+
Registered via [`RegisterCompilationEndAction`](https://github.com/jonathanalgar/CustomCode-Analyzer/blob/33c0d5ce0a762236a495ebc940b688e9e14cd901/src/CustomCode-Analyzer/Analyzer.cs#L414-L417), this phase runs after all symbols have been processed and the semantic model is complete. For example, it ensures exactly one `[OSInterface]` exists across your project by maintaining a `ConcurrentDictionary` of interface declarations and validating their uniqueness (`NoSingleInterfaceRule` or `ManyInterfacesRule`). These diagnostics may appear with a slight delay as they require complete semantic analysis.
62
+
63
+
#### Code fixes for certain rules
64
+
65
+
Wherever we can infer a single, unambiguous fix, we provide an **automated code fix** through the Roslyn `CodeFixProvider`. Currently, code fixes are available for these rules:
66
+
67
+
| Rule description | OS-ELG-MODL code | Action performed |
|**Name begins with underscores**| 05022 | Remove leading `_` in method names |
75
+
|**Unsupported type mapping**| 05017 | Change field/property type to match `DataType`|
76
+
77
+
The code fix suggestions appear as "lightbulb" actions (or "quick actions") in your IDE. If you accept the fix, the analyzer modifies your source code to make it compliant with the respective rule.
32
78
33
79
## How to use
34
80
35
-
### Visual Studio 2022 (Enterprise, Pro and Community editions)
81
+
### Visual Studio 2022 (Enterprise, Pro and, Community editions)
36
82
37
83
You can use the auto-updating extension from the Visual Studio Marketplace. Simply [install the extension from the Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=JonathanAlgar.CustomCodeAnalyzer).
38
84
39
85
If your project references the External Libraries SDK (`OutSystems.ExternalLibraries.SDK`), the extension should automatically start providing feedback on your code.
40
86
41
-
To ensure real-time feedback for [compilation end phase](#analyzer-phases) rules (not just during builds), you need to configure your Visual Studio's background analysis:
87
+
To ensure real-time feedback for [compilation end phase](#analyzer-phases) rules (and not just at the point of build), you need to configure your Visual Studio's background analysis:
42
88
43
89
1. Select **Tools** > **Options**.
44
90
1. From the left menu select **C#** > **Advanced**.
45
91
1. Set both **Run background code analysis** for and **Show compiler errors and warnings** to **Entire solution**.
46
92
1. Make sure the **Run code analysis in separate process box** is unchecked.
47
93
94
+
> :bulb: To ensure the extension automatically updates to the latest version, you should enable auto-updates in Visual Studio. Go to **Tools** > **Options** > **Environment** > **Extensions** and make sure **Automatically update extensions** is checked.
95
+
48
96
### Others
49
97
50
98
Add the [NuGet package](https://www.nuget.org/packages/CustomCode.Analyzer/) as a dev dependency to your ODC external libraries project:
@@ -53,21 +101,23 @@ Add the [NuGet package](https://www.nuget.org/packages/CustomCode.Analyzer/) as
53
101
54
102
If your project references the External Libraries SDK (`OutSystems.ExternalLibraries.SDK`), the package should automatically start providing feedback on your code.
55
103
104
+
The NuGet package cannot be automatically updated, so be sure to update regularlrly to get the latest features.
105
+
56
106
#### Visual Studio Code
57
107
58
-
To ensure real-time feedback for [compilation end phase](#analyzer-phases) rules (not just during builds), you need to configure your Visual Studio Code's background analysis:
108
+
To ensure real-time feedback for [compilation end phase](#analyzer-phases) rules (and not just at the point of build), you need to configure your Visual Studio's background analysis:
59
109
60
110
1. Open the command palette (_Ctrl+Shift+P_).
61
111
1. Search for "roslyn". Set the **Dotnet › Background Analysis: Analyzer Diagnostics Scope** to **fullSolution**.
62
112
63
-
> :bulb: Auto-updating extensions for Visual Studio Code and Rider are in the works.
113
+
> :bug: For the [code fix](#code-fixes-for-certain-rules) to work, you need to be switch to using the pre-release version of the C# extension. See [this issue](https://github.com/dotnet/vscode-csharp/issues/7802).
64
114
65
115
## TODO
66
116
67
117
See [here](https://github.com/jonathanalgar/CustomCode-Analyzer/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement).
68
118
69
-
## Contributing
119
+
## Feedback and contributions
70
120
71
-
Please report bugs and feature requests [here](https://github.com/jonathanalgar/CustomCode-Analyzer/issues/new/choose).
121
+
Please report bugs and feature requests [here](https://github.com/jonathanalgar/CustomCode-Analyzer/issues/new/choose). Feel free to leave general feedback on the [OutSystems Community Forum post](https://www.outsystems.com/forums/discussion/100963/odc-external-libraries-custom-code-analyzer/).
72
122
73
-
PRs are welcome. Code quality improvements, new features (especially those unassigned and listed [here](https://github.com/jonathanalgar/CustomCode-Analyzer/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement)) and documentation improvements are all welcome 🤗 All changes to Analyzer code should pass all existing tests (`dotnet test`) and all new features should be covered by new tests.
123
+
PRs are welcome. Code quality improvements, new features (especially those unassigned and listed [here](https://github.com/jonathanalgar/CustomCode-Analyzer/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement)), and documentation improvements are all welcome 🤗 All changes to Analyzer code should pass all existing tests (`dotnet test`), and all new features should be covered by new tests. Please format any new code with [csharpier](https://csharpier.com/).
0 commit comments