Skip to content

Commit

Permalink
gopls/internal/migrate.sh: a script to migrate internal/lsp to gopls/
Browse files Browse the repository at this point in the history
Add a script that does the migration of the internal/lsp directory to
gopls/internal/lsp. This is done in a separate CL so that in-progress
CLs can rebase on top of *this CL*, run this script, and then rebase to
tip.

For golang/go#54509

Change-Id: I6f529c1e4ba29b4d88dc26278d54a055f1ef212e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/426795
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
  • Loading branch information
findleyr committed Sep 7, 2022
1 parent 83d7619 commit c1dd25e
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions gopls/internal/migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
#
# Copyright 2022 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
#
# Migrates the internal/lsp directory to gopls/internal/lsp. Run this script
# from the root of x/tools to migrate in-progress CLs.
#
# See golang/go#54509 for more details. This script may be deleted once a
# reasonable amount of time has passed such that all active in-progress CLs
# have been rebased.

set -eu

# A portable -i flag. Darwin requires two parameters.
# See https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux
# for more details.
sedi=(-i)
case "$(uname)" in
Darwin*) sedi=(-i "")
esac

# mvpath moves the directory at the relative path $1 to the relative path $2,
# moving files and rewriting import paths.
#
# It uses heuristics to identify import path literals, and therefore may be
# imprecise.
function mvpath() {
# If the source also doesn't exist, it may have already been moved.
# Skip so that this script is idempotent.
if [[ ! -d $1 ]]; then
echo "WARNING: skipping nonexistent source directory $1"
return 0
fi

# git can sometimes leave behind empty directories, which can change the
# behavior of the mv command below.
if [[ -d $2 ]] || [[ -f $2 ]]; then
echo "ERROR: destination $2 already exists"
exit 1
fi

mv $1 $2

local old="golang.org/x/tools/$1"
local new="golang.org/x/tools/$2"

# Replace instances of the old import path with the new. This is imprecise,
# but we are a bit careful to avoid replacing golang.org/x/tools/foox with
# golang.org/x/tools/barx when moving foo->bar: the occurrence of the import
# path must be followed by whitespace, /, or a closing " or `.
local replace="s:${old}\([[:space:]/\"\`]\):${new}\1:g"
find . -type f \( \
-name ".git" -prune -o \
-name "*.go" -o \
-name "*.in" -o \
-name "*.golden" -o \
-name "*.hlp" -o \
-name "*.md" \) \
-exec sed "${sedi[@]}" -e $replace {} \;
}

mvpath internal/lsp/diff internal/diff
mvpath internal/lsp/fuzzy internal/fuzzy
mvpath internal/lsp/debug/tag internal/event/tag
mvpath internal/lsp/bug internal/bug
mvpath internal/lsp gopls/internal/lsp

0 comments on commit c1dd25e

Please sign in to comment.