From 1acf6e5b7face357e710737fa0b80bce42af8a31 Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Thu, 23 Mar 2023 15:06:31 +0000 Subject: [PATCH] Fix automatic requires being placed inside of comment Fixes #327 --- CHANGELOG.md | 1 + src/operations/Completion.cpp | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 515d6110..6b0e7d02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fixed server crash when auto require imports is enabled and there is a type-asserted require present in the file (`require(location) :: any`) - Fixed additional automatic service imports when completing an automatic require import being placed before a hot comment (such as `--!strict`) +- Fixed automatic require import being placed incorrectly we also autocomplete a service. This can be shown when there is a multiline comment, and the service is imported above that comment, but the require gets imported inside of the comment incorrectly. ## [1.18.0] - 2023-03-20 diff --git a/src/operations/Completion.cpp b/src/operations/Completion.cpp index 0aa308d0..ff5c6d4f 100644 --- a/src/operations/Completion.cpp +++ b/src/operations/Completion.cpp @@ -379,15 +379,10 @@ void WorkspaceFolder::suggestImports(const Luau::ModuleName& moduleName, const L if (!isRelative) { // Service will be the first part of the path + // If we haven't imported the service already, then we auto-import it auto service = requirePath.substr(0, requirePath.find('/')); if (serviceVisitor.serviceLineMap.find(service) == serviceVisitor.serviceLineMap.end()) - { - // If we haven't imported the service, then we auto-import it textEdits.emplace_back(createServiceTextEdit(service, serviceVisitor.findBestLine(service, hotCommentsLineNumber))); - - // Increment the require line number to account for the new service import - lineNumber += 1; - } } textEdits.emplace_back(createRequireTextEdit(node->name, require, lineNumber));