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

Commit

Permalink
Prioritize current project import suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan-at-work committed Jul 17, 2018
1 parent 81e7053 commit dae43db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/goPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function getImportablePackages(filePath: string, useCache: boolean = fals
if (!foundPkgRootDir) {
// try to guess package root dir
let vendorIndex = pkgPath.indexOf('/vendor/');
if (vendorIndex !== -1 ) {
if (vendorIndex !== -1) {
foundPkgRootDir = path.join(currentWorkspace, pkgPath.substring(0, vendorIndex).replace('/', path.sep));
pkgRootDirs.set(fileDirPath, foundPkgRootDir);
}
Expand Down
11 changes: 9 additions & 2 deletions src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import vscode = require('vscode');
import cp = require('child_process');
import { getBinPath, getParametersAndReturnType, parseFilePrelude, isPositionInString, goKeywords, getToolsEnvVars, guessPackageNameFromFile, goBuiltinTypes, byteOffsetAt } from './util';
import { getCurrentGoPath, getBinPath, getParametersAndReturnType, parseFilePrelude, isPositionInString, goKeywords, getToolsEnvVars, guessPackageNameFromFile, goBuiltinTypes, byteOffsetAt } from './util';
import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
import { getTextEditForAddImport } from './goImport';
import { getImportablePackages } from './goPackages';
Expand Down Expand Up @@ -354,6 +354,7 @@ 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);

this.pkgsList.forEach((pkgName: string, pkgPath: string) => {
if (pkgName.startsWith(word) && !suggestionSet.has(pkgName)) {
Expand All @@ -371,9 +372,15 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider {
// Add same sortText to the unimported packages so that they appear after the suggestions from gocode
const isStandardPackage = !item.detail.includes('.');
item.sortText = isStandardPackage ? 'za' : 'zb';
completionItems.push(item);
if (pkgPath.startsWith(rootPath)) {
item.sortText = 'a';
completionItems.unshift(item);
} else {
completionItems.push(item);
}
}
});

return completionItems;
}

Expand Down

0 comments on commit dae43db

Please sign in to comment.