Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
fix project import prioritization to account for multi root projects
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan-at-work committed Jul 17, 2018
1 parent dae43db commit dd218e2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/goSuggest.ts
Expand Up @@ -5,9 +5,11 @@

'use strict';

import path = require('path');
import vscode = require('vscode');
import cp = require('child_process');
import { getCurrentGoPath, getBinPath, getParametersAndReturnType, parseFilePrelude, isPositionInString, goKeywords, getToolsEnvVars, guessPackageNameFromFile, goBuiltinTypes, byteOffsetAt } from './util';
import { getCurrentGoWorkspaceFromGOPATH } from './goPath';
import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
import { getTextEditForAddImport } from './goImport';
import { getImportablePackages } from './goPackages';
Expand Down Expand Up @@ -354,7 +356,14 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
private getMatchingPackages(word: string, suggestionSet: Set<string>): vscode.CompletionItem[] {
if (!word) return [];
let completionItems = [];
const rootPath = vscode.workspace.rootPath.slice(getCurrentGoPath().length + 5);
const editor = vscode.window.activeTextEditor;
const documentUri = editor ? editor.document.uri : null;
const cwd = path.dirname(documentUri ? documentUri.path : "");
const workSpaceFolder = vscode.workspace.getWorkspaceFolder(documentUri);
const goPath = getCurrentGoPath();
const goWorkSpace = getCurrentGoWorkspaceFromGOPATH(goPath, cwd);
const workspaceRootPath = workSpaceFolder ? workSpaceFolder.uri.path : cwd;
const rootPath = workspaceRootPath.slice(goWorkSpace.length + 1);

this.pkgsList.forEach((pkgName: string, pkgPath: string) => {
if (pkgName.startsWith(word) && !suggestionSet.has(pkgName)) {
Expand Down

0 comments on commit dd218e2

Please sign in to comment.