Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't suggest private things from other files #160

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/unsafe/providers/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const reQuotedValueInString = /['"](?:[^'"\\]|\\.)*['"]/g;
const reMixinReference = /.*@include\s+(.*)/;
const reComment = /^(\/(\/|\*)|\*)/;
const reQuotes = /['"]/;
const rePrivate = /^\$[_-].*$/;

/**
* Returns `true` if the path is not present in the document.
Expand Down Expand Up @@ -136,6 +137,12 @@ function createVariableCompletionItems(
const fsPath = getDocumentPath(filepath, isImplicitlyImport ? symbol.filepath : symbol.document);

symbol.variables.forEach(variable => {
const isPrivate = variable.name.match(rePrivate);
if (symbol.filepath !== filepath && isPrivate) {
// Don't suggest private variables from other files
return;
}

const color = getVariableColor(variable.value || '');
const completionKind = color ? CompletionItemKind.Color : CompletionItemKind.Variable;

Expand Down Expand Up @@ -176,6 +183,12 @@ function createMixinCompletionItems(
const fsPath = getDocumentPath(filepath, isImplicitlyImport ? symbol.filepath : symbol.document);

symbol.mixins.forEach(mixin => {
const isPrivate = mixin.name.match(rePrivate);
if (symbol.filepath !== filepath && isPrivate) {
// Don't suggest private mixins from other files
return;
}

// Add 'implicitly' prefix for Path if the file imported implicitly
let detailPath = fsPath;
if (isImplicitlyImport && settings.implicitlyLabel) {
Expand Down Expand Up @@ -208,6 +221,12 @@ function createFunctionCompletionItems(
const fsPath = getDocumentPath(filepath, isImplicitlyImport ? symbol.filepath : symbol.document);

symbol.functions.forEach(func => {
const isPrivate = func.name.match(rePrivate);
if (symbol.filepath !== filepath && isPrivate) {
// Don't suggest private functions from other files
return;
}

// Add 'implicitly' prefix for Path if the file imported implicitly
let detailPath = fsPath;
if (isImplicitlyImport && settings.implicitlyLabel) {
Expand Down