Skip to content

Commit 0505f2a

Browse files
committed
Refactor for corner cases
1 parent 5673d88 commit 0505f2a

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/goImport.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,14 @@ export function listPackages(excludeImportedPkgs: boolean = false): Thenable<str
7474
return;
7575
}
7676

77-
let magicVendorString = 'vendor/';
77+
let magicVendorString = '/vendor/';
7878
let vendorIndex = pkg.indexOf(magicVendorString);
79-
79+
if (vendorIndex === -1) {
80+
magicVendorString = 'vendor/';
81+
if (pkg.startsWith(magicVendorString)) {
82+
vendorIndex = 0;
83+
}
84+
}
8085
// Check if current file and the vendor pkg belong to the same root project
8186
// If yes, then vendor pkg can be replaced with its relative path to the "vendor" folder
8287
// If not, then the vendor pkg should not be allowed to be imported.

src/goSuggest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
218218
let pkgName = index === -1 ? pkg : pkg.substr(index + 1);
219219
// pkgs from gopkg.in will be of the form gopkg.in/user/somepkg.v3
220220
if (pkg.match(/gopkg\.in\/.*\.v\d+/)) {
221-
pkgName = pkgName.substr(0, pkgName.indexOf('.v'));
221+
pkgName = pkgName.substr(0, pkgName.lastIndexOf('.v'));
222222
}
223223
return {
224224
name: pkgName,

0 commit comments

Comments
 (0)