Skip to content

Commit 1a9c923

Browse files
Localize exception messages for gladstone/roslyn integration (#78063)
2 parents 08759c1 + 2b57507 commit 1a9c923

34 files changed

+978
-13
lines changed

src/Features/Core/Portable/Extensions/ExtensionFolder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void RegisterAssembly(string assemblyFilePath)
118118
// If this throws, it also indicated a bug in gladstone that must be fixed. As such, it is ok if this
119119
// tears down the extension service in OOP.
120120
if (_assemblyFilePathToHandlers.ContainsKey(assemblyFilePath))
121-
throw new InvalidOperationException($"Extension '{assemblyFilePath}' is already registered.");
121+
throw new InvalidOperationException(string.Format(FeaturesResources.Extension_0_is_already_registered, assemblyFilePath));
122122

123123
_assemblyFilePathToHandlers = _assemblyFilePathToHandlers.Add(
124124
assemblyFilePath,
@@ -141,7 +141,7 @@ public void RegisterAssembly(string assemblyFilePath)
141141
// If this throws, it also indicated a bug in gladstone that must be fixed. As such, it is ok if this
142142
// tears down the extension service in OOP.
143143
if (!_assemblyFilePathToHandlers.TryGetValue(assemblyFilePath, out var lazyHandlers))
144-
throw new InvalidOperationException($"Extension '{assemblyFilePath}' was not registered.");
144+
throw new InvalidOperationException(string.Format(FeaturesResources.Extension_0_was_not_registered, assemblyFilePath));
145145

146146
_assemblyFilePathToHandlers = _assemblyFilePathToHandlers.Remove(assemblyFilePath);
147147
return (_assemblyFilePathToHandlers.Count == 0, lazyHandlers);
@@ -156,7 +156,7 @@ public async ValueTask<ExtensionMessageNames> GetExtensionMessageNamesAsync(stri
156156
// If this throws, it also indicated a bug in gladstone that must be fixed. As such, it is ok if this
157157
// tears down the extension service in OOP.
158158
if (!_assemblyFilePathToHandlers.TryGetValue(assemblyFilePath, out var lazyHandlers))
159-
throw new InvalidOperationException($"Extension '{assemblyFilePath}' was not registered.");
159+
throw new InvalidOperationException(string.Format(FeaturesResources.Extension_0_was_not_registered, assemblyFilePath));
160160

161161
// Handlers already encapsulates any extension-level exceptions that occurred when loading the assembly.
162162
// As such, we don't need our own try/catch here. We can just return the result directly.

src/Features/Core/Portable/Extensions/ExtensionMessageHandlerService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private sealed partial class ExtensionMessageHandlerService(
6060
private static string GetAssemblyFolderPath(string assemblyFilePath)
6161
{
6262
return Path.GetDirectoryName(assemblyFilePath)
63-
?? throw new InvalidOperationException($"Unable to get the directory name for {assemblyFilePath}.");
63+
?? throw new InvalidOperationException(string.Format(FeaturesResources.Unable_to_get_the_directory_name_for_0, assemblyFilePath));
6464
}
6565

6666
private void ClearCachedHandlers_WhileUnderLock()
@@ -114,7 +114,7 @@ private ValueTask UnregisterExtensionInCurrentProcessAsync(string assemblyFilePa
114114
lock (_gate)
115115
{
116116
if (!_folderPathToExtensionFolder.TryGetValue(assemblyFolderPath, out var extensionFolder))
117-
throw new InvalidOperationException($"No extension registered as '{assemblyFolderPath}'");
117+
throw new InvalidOperationException(string.Format(FeaturesResources.No_extension_registered_as_0, assemblyFolderPath));
118118

119119
// Clear out the cached handler names. They will be recomputed the next time we need them.
120120
ClearCachedHandlers_WhileUnderLock();
@@ -174,7 +174,7 @@ private async ValueTask<ExtensionMessageNames> GetExtensionMessageNamesInCurrent
174174
// Throwing here indicates a bug in the gladstone client itself. So we want this to bubble outwards as a
175175
// failure that disables extension running in the OOP process. This must be fixed by gladstone.
176176
if (!_folderPathToExtensionFolder.TryGetValue(assemblyFolderPath, out var extensionFolder))
177-
throw new InvalidOperationException($"No extensions registered at '{assemblyFolderPath}'");
177+
throw new InvalidOperationException(string.Format(FeaturesResources.No_extensions_registered_at_0, assemblyFolderPath));
178178

179179
// Note if loading the extension assembly failed (due to issues in the extension itself), then the exception
180180
// produced by it will be passed outwards as data in the ExtensionMessageNames result.
@@ -219,14 +219,14 @@ private async ValueTask<ExtensionMessageResult> HandleExtensionMessageInCurrentP
219219
// bug in the gladstone client itself (as it allowed calling into an lsp message that never had
220220
// registered handlers). So we want this to bubble outwards as a failure that disables extension
221221
// running in the OOP process. This must be fixed by gladstone.
222-
throw new InvalidOperationException($"No handler found for message {messageName}.");
222+
throw new InvalidOperationException(string.Format(FeaturesResources.No_handler_found_for_message_0, messageName));
223223
}
224224

225225
// Throwing here indicates a bug in the gladstone client itself (as it allowed calling into an lsp message
226226
// that had multiple registered handlers). So we want this to bubble outwards as a failure that disables
227227
// extension running in the OOP process. This must be fixed by gladstone.
228228
if (handlers.Length > 1)
229-
throw new InvalidOperationException($"Multiple handlers found for message {messageName}.");
229+
throw new InvalidOperationException(string.Format(FeaturesResources.Multiple_handlers_found_for_message_0, messageName));
230230

231231
var handler = (IExtensionMessageHandlerWrapper<TArgument>)handlers[0];
232232

src/Features/Core/Portable/FeaturesResources.resx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,4 +3205,25 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
32053205
<value>Convert to 'field' property</value>
32063206
<comment>{Locked="field"} "field" is C# keyword and should not be localized.</comment>
32073207
</data>
3208+
<data name="Extension_0_is_already_registered" xml:space="preserve">
3209+
<value>Extension '{0}' is already registered.</value>
3210+
</data>
3211+
<data name="Extension_0_was_not_registered" xml:space="preserve">
3212+
<value>Extension '{0}' was not registered.</value>
3213+
</data>
3214+
<data name="Unable_to_get_the_directory_name_for_0" xml:space="preserve">
3215+
<value>Unable to get the directory name for {0}.</value>
3216+
</data>
3217+
<data name="No_extension_registered_as_0" xml:space="preserve">
3218+
<value>No extension registered as '{0}'.</value>
3219+
</data>
3220+
<data name="No_extensions_registered_at_0" xml:space="preserve">
3221+
<value>No extensions registered at '{0}'.</value>
3222+
</data>
3223+
<data name="No_handler_found_for_message_0" xml:space="preserve">
3224+
<value>No handler found for message {0}.</value>
3225+
</data>
3226+
<data name="Multiple_handlers_found_for_message_0" xml:space="preserve">
3227+
<value>Multiple handlers found for message {0}.</value>
3228+
</data>
32083229
</root>

src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Features/Core/Portable/xlf/FeaturesResources.de.xlf

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Features/Core/Portable/xlf/FeaturesResources.es.xlf

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)