From 9316eaafc3797e4a448e49bb261dca18453f0267 Mon Sep 17 00:00:00 2001 From: Techatrix Date: Tue, 3 Dec 2024 15:28:42 +0100 Subject: [PATCH] no string conversion code actions for strings with carriage returns --- src/features/code_actions.zig | 2 +- tests/lsp_features/code_actions.zig | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/features/code_actions.zig b/src/features/code_actions.zig index e0252724f..888695fa7 100644 --- a/src/features/code_actions.zig +++ b/src/features/code_actions.zig @@ -149,7 +149,7 @@ pub fn generateStringLiteralCodeActions( }; // Check for disallowed characters and utf-8 validity for (parsed) |c| { - if (c == '\n' or c == '\r') continue; + if (c == '\n') continue; if (std.ascii.isControl(c)) return; } if (!std.unicode.utf8ValidateSlice(parsed)) return; diff --git a/tests/lsp_features/code_actions.zig b/tests/lsp_features/code_actions.zig index c78c3a7c2..c4587101f 100644 --- a/tests/lsp_features/code_actions.zig +++ b/tests/lsp_features/code_actions.zig @@ -807,6 +807,12 @@ test "convert string literal to multiline - invalid" { , \\const foo = "\tWe use tabs"; ); + // A Multi-Line String Literals can't contain carriage returns + try testConvertString( + \\const foo = "\r"; + , + \\const foo = "\r"; + ); // Not in @import try testConvertString( \\const std = @import("std");