Skip to content

Commit

Permalink
fix: use current document directly
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmlnc committed Nov 30, 2019
1 parent 9033abc commit 6bdd703
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 61 deletions.
4 changes: 2 additions & 2 deletions src/providers/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import StorageService from '../services/storage';

import { parseDocument } from '../services/parser';
import { getSymbolsRelatedToDocument } from '../utils/symbols';
import { getCurrentDocumentImportPaths, getDocumentPath } from '../utils/document';
import { getDocumentPath } from '../utils/document';
import { getCurrentWord, getLimitedString, getTextBeforePosition } from '../utils/string';
import { getVariableColor } from '../utils/color';

Expand Down Expand Up @@ -242,7 +242,7 @@ export function doCompletion(
storage.set(documentPath, resource.symbols);

const symbolsList = getSymbolsRelatedToDocument(storage, documentPath);
const documentImports = getCurrentDocumentImportPaths(symbolsList, documentPath);
const documentImports = resource.symbols.imports.map(x => x.filepath);
const context = createCompletionContext(document, offset, settings);

// Drop suggestions inside `//` and `/* */` comments
Expand Down
4 changes: 2 additions & 2 deletions src/providers/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import StorageService from '../services/storage';

import { parseDocument } from '../services/parser';
import { getSymbolsRelatedToDocument } from '../utils/symbols';
import { getCurrentDocumentImportPaths, getDocumentPath } from '../utils/document';
import { getDocumentPath } from '../utils/document';
import { getLimitedString } from '../utils/string';

/**
Expand Down Expand Up @@ -146,7 +146,7 @@ export function doHover(document: TextDocument, offset: number, storage: Storage
storage.set(documentPath, resource.symbols);

const symbolsList = getSymbolsRelatedToDocument(storage, documentPath);
const documentImports = getCurrentDocumentImportPaths(symbolsList, documentPath);
const documentImports = resource.symbols.imports.map(x => x.filepath);
const symbol = getSymbol(symbolsList, identifier, documentPath);

// Content for Hover popup
Expand Down
43 changes: 1 addition & 42 deletions src/test/utils/document.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,9 @@

import * as assert from 'assert';

import { ISymbols } from '../../types/symbols';
import { getCurrentDocumentImportPaths, getDocumentPath } from '../../utils/document';
import { getDocumentPath } from '../../utils/document';

describe('Utils/Document', () => {
it('getCurrentDocumentImports', () => {
const symbolsList: ISymbols[] = [
{
document: 'a.scss',
mixins: [],
functions: [],
variables: [],
imports: [
{
filepath: 'b.scss',
css: false,
dynamic: false
}
]
},
{
document: 'b.scss',
mixins: [],
functions: [],
variables: [],
imports: [
{
filepath: 'a.scss',
css: false,
dynamic: false
},
{
filepath: 'c.scss',
css: false,
dynamic: false
}
]
}
];

const imports = getCurrentDocumentImportPaths(symbolsList, 'b.scss');

assert.equal(imports.length, 2);
});

it('getDocumentPath', () => {
assert.equal(getDocumentPath('test/file.scss', 'test/includes/a.scss'), 'includes/a.scss');
assert.equal(getDocumentPath('test/includes/a.scss', 'test/file.scss'), '../file.scss');
Expand Down
15 changes: 0 additions & 15 deletions src/utils/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@

import * as path from 'path';

import { ISymbols } from '../types/symbols';

/**
* Returns imports for document.
*/
export function getCurrentDocumentImportPaths(symbolsList: ISymbols[], currentPath: string): string[] {
for (let i = 0; i < symbolsList.length; i++) {
if (symbolsList[i].document === currentPath) {
return symbolsList[i].imports.map(x => x.filepath);
}
}

return [];
}

/**
* Returns the path to the document, relative to the current document.
*/
Expand Down

0 comments on commit 6bdd703

Please sign in to comment.