Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File IO abstraction part 6: Simplify SourceFileFactory #16242

Merged
merged 4 commits into from
Jan 30, 2025

Conversation

shenglol
Copy link
Contributor

@shenglol shenglol commented Jan 30, 2025

Extracting more changes for my main file I/O migration branch...

This PR introduces two key improvements:

  1. Simplifying SourceFileFactory – It merges multiple factory methods into one and refines the source file creation logic, allowing the removal of BicepCompilationManager.CreateSourceFile.

  2. Reducing unnecessary SourceFileFactory usage – Many language server integration tests previously relied on SourceFileFactory to create source files, resulting in unnecessary parsing, even though they only needed the source file URI, contents, and line starts. This PR introduces a new helper test class, LanguageClientFile, eliminating the need to call SourceFileFactory and providing several benefits:

    • It improves test readability and maintainability.
    • Tests runs slightly faster as there is no unnecessary file parsing before making LSP requests.
    • References to SourceFileFactory get reduced from about 100 to 29. This is particularly important for narrowing the file I/O migration scope.
Microsoft Reviewers: Open in CodeFlow

Copy link
Contributor

github-actions bot commented Jan 30, 2025

Test this change out locally with the following install scripts (Action run 13061804772)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 13061804772
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 13061804772"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 13061804772
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 13061804772"

{
[new Uri("file:///mod.bicep")] = moduleContent,
[new Uri("file:///mod2.bicep")] = moduleContent,
Copy link
Contributor Author

@shenglol shenglol Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of duplicate code in these tests that could be further simplified, but that's outside the scope of this PR.

@shenglol shenglol force-pushed the shenglol/file-io-abstraction-part-6 branch from 547d48a to 0c91fd9 Compare January 30, 2025 05:21
@shenglol shenglol force-pushed the shenglol/file-io-abstraction-part-6 branch from 0c91fd9 to 3fb7bcc Compare January 30, 2025 05:21
Copy link
Contributor

github-actions bot commented Jan 30, 2025

Dotnet Test Results

    78 files   -     39      78 suites   - 39   33m 30s ⏱️ - 13m 19s
11 710 tests  -     10  11 710 ✅  -     10  0 💤 ±0  0 ❌ ±0 
27 178 runs   - 13 575  27 178 ✅  - 13 575  0 💤 ±0  0 ❌ ±0 

Results for commit f3cb2fc. ± Comparison against base commit 7a77c7f.

This pull request removes 1807 and adds 638 tests. Note that renamed tests count towards both.

		nestedProp1: 1
		nestedProp2: 2
		prop1: true
		prop2: false
	1
	2
	\$'")
	prop1: true
	prop2: false
…
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
�ӽ\u000e�0\u0010\u0007��>\u0005OPz�і���Wh�ďP�@$1���`b"�\u0005����\u000e�\zm���u���K-u�c)&��&\u001a��A
\u0002̓\u0012�\u0010�"�\u001f�][7�£�q�\u000fB\u001b��P\u00169�Ģ�\u000cHf�R��k��\u001aDg���֟|u��XW�o(�\u001a��h0�����D��\u0014
 C�Ï��� ��ϒ�?�����\u0004A\u0010\u0004�\u0012\u001eH�3C\u0000\u000c\u0000\u0000,"The path: index.json was not found in artifact contents")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
��K
�0\u0010\u0006�=E�\u0001Ҽ�X�{7�\u001b\u000f\u0010�\u0011+��6BA���B\hqӇ`�ef ��?$ܚv
&��!J����QGI�q�äFL?QD��\u0011B�\u001d~�w�ƚڍ2�^?�/��y\u0001	�b�5�YD�fRQ�p����b\\u0019{L�2����Kٵ\u0017}�s\u001f���z���[�����\u0001R��s.\u0010UQ�]�'������]	m\u0005��l\u0003�\u001e�`�\u000f���}��<���<\u0000\u001a�\u0015\u0000\u0000\u000c\u0000\u0000,"Value cannot be null. (Parameter 'source')")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
��M\u000b�0\u0018\u0007��\u0014�\u000f0�>
<\u0004\u001d2��k�\u001cd��\u001a\u0008}��!:�tQ\u000b��=�g\u001b�\u0007�\u001b�,�NMY!ɤ�@�%9���"\\u0001�\u001e0��+\u0001\u0000l�o�յ�ui[\u0019�\u001fD\u0003��,7\u0011Q,���D �\u0018\u000b$�ؽC�\u001e	�E��(+RӠSu.�����t:<�o�'���L9�3�K\u001b~J\u0019�R\u0008i�?J&�<�7/Nv�U<�/��ěB;��ݓ�8�3�;,h\u0010�\u0000\u000c\u0000\u0000,"'7' is an invalid end of a number. Expected a delimiter. Path: $.INVALID_JSON | LineNumber: 0 | BytePositionInLine: 20.")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003�ӽ
�0\u0010\u0007��>E� �K�M�BЂ\u001f4�&ł����R[���\u001c�]8�"��~[�C�z�H�L��AT\u0010��\u000f0G��\u0005\u0018�<W��~�MFt>�6��Ĭ\u001f$
��TW%je��\u0006@�$i\u0014nbm?YC~��Xv�⚛\u0013g߸���jX��ɨ��}kƧ�\u0003H�����\u0007\u001a�J��/��?�����\u0006I�$�\u001a�dĔ\u001c\u0000\u000c\u0000\u0000,"The path: index.json was not found in artifact contents")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003��K
�0\u0010\u0006�=E�\u0001b�<+t�Fp�\u0001b;b���V(�w7]��\u00167}\u0008�[f\u0006fB�C�{�n��PՄ\u000bn�\u0004��:J���\u000e\u0013\u001a1�F\u0011�RQ�p;�&=�uc+��\u001c�~Ph�m�\u001cb��	uh(#Qh����Ւ�\u001a�pi�s�\u0015)��Rߊ�=\u001fj_��ހ��M7�[�)\u0017��\u0001B��S�\u0010URJ��Y2������P@[B�@���\u0008U��'{���n��y�t^�av\u0000\u000c\u0000\u0000,"Value cannot be null. (Parameter 'source')")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003���\u000b�0\u0014\u0007��+�����~\u0019x\u0008:d�\u0005A�\u00189�@\u000b5\u0010�盇�tQ\u000b��=xo��C�N7+�SSV(`��\u0011\u0018\u001a�\u0004c��-�$ �\u0005\u0003,��\u0000�f�I:ܫZ�v�)z� �����DD\u0006�J�0A*�p5�w��;\u0012���QV��A��Z��y_�����x��x=>�\u001fS\u0006�\u000e`�\u001f3\u0002���V�I2����xqrXl��q��&�\u001c�
��\u001c�q��=\u0001��<�\u0000\u000c\u0000\u0000,"'7' is an invalid end of a number. Expected a delimiter. Path: $.INVALID_JSON | LineNumber: 0 | BytePositionInLine: 20.")
Bicep.Core.IntegrationTests.DecompilationTests ‑ Decompiler_handles_banned_function_replacement ("createArray(1, 2, 3)","array","[
  1
  2
  3
]")
Bicep.Core.IntegrationTests.DecompilationTests ‑ Decompiler_handles_banned_function_replacement ("createObject('key', 'value')","object","{
  key: 'value'
}")
Bicep.Core.IntegrationTests.DecompilationTests ‑ Decompiler_handles_strings_with_newlines ("
","\n")
Bicep.Core.IntegrationTests.DecompilationTests ‑ Decompiler_handles_strings_with_newlines ("
","\r\n")
…

♻️ This comment has been updated with latest results.

Copy link
Member

@majastrz majastrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@shenglol shenglol enabled auto-merge (squash) January 30, 2025 21:39
@shenglol shenglol merged commit 497f9c9 into main Jan 30, 2025
47 checks passed
@shenglol shenglol deleted the shenglol/file-io-abstraction-part-6 branch January 30, 2025 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants