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

Add protoSrcsDir config option #150

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/proto3Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export class Proto3Configuration {
this._config.get<string>('compile_all_path', activeWorkspaceFolder.uri.path));
}

public getProtoSrcsDir(): string {
return this._configResolver.resolve(
this._config.get<string>('protoSrcsDir', ''));
}

public getProtocArgs(): string[] {
return this._configResolver.resolve(
this._config.get<string[]>('options', []));
Expand Down
10 changes: 8 additions & 2 deletions src/proto3Definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import fg = require('fast-glob');
import { guessScope, Proto3ScopeKind } from './proto3ScopeGuesser';
import { Proto3Import } from './proto3Import';
import { Proto3Primitive } from './proto3Primitive';
import { Proto3Configuration } from './proto3Configuration';


export class Proto3DefinitionProvider implements vscode.DefinitionProvider {
private _config: Proto3Configuration;

constructor(workspaceFolder?: vscode.WorkspaceFolder) {
this._config = Proto3Configuration.Instance(workspaceFolder);
}

public async provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Definition> {

Expand Down Expand Up @@ -58,7 +64,7 @@ export class Proto3DefinitionProvider implements vscode.DefinitionProvider {

private async findEnumOrMessageDefinition(document: vscode.TextDocument, target: string): Promise<vscode.Location> {

const searchPaths = Proto3Import.getImportedFilePathsOnDocument(document);
const searchPaths = Proto3Import.getImportedFilePathsOnDocument(document, this._config.getProtoSrcsDir());

const files = [
document.uri.fsPath,
Expand All @@ -81,7 +87,7 @@ export class Proto3DefinitionProvider implements vscode.DefinitionProvider {
}

private async findImportDefinition(importFileName: string): Promise<vscode.Location> {
const files = await fg(path.join(vscode.workspace.rootPath, '**', importFileName));
const files = await fg(path.join(vscode.workspace.rootPath, this._config.getProtoSrcsDir(), '**', importFileName));
const importPath = files[0].toString();
// const data = fs.readFileSync(importPath);
// const lines = data.toString().split('\n');
Expand Down
4 changes: 2 additions & 2 deletions src/proto3Import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export module Proto3Import {

export const importStatementRegex = new RegExp(/^\s*import\s+('|")(.+\.proto)('|")\s*;\s*$/gim);

export const getImportedFilePathsOnDocument = (document: vscode.TextDocument) => {
export const getImportedFilePathsOnDocument = (document: vscode.TextDocument, protoSrcsDir: string) => {
const fullDocument = document.getText();
let importStatement: RegExpExecArray;
let importPaths = [];
while (importStatement = importStatementRegex.exec(fullDocument)) {
const protoFileName = importStatement[2];
const searchPath = path.join(vscode.workspace.rootPath, '**', protoFileName);
const searchPath = path.join(vscode.workspace.rootPath, protoSrcsDir, '**', protoFileName);
importPaths.push(searchPath);
}
return importPaths;
Expand Down
3 changes: 2 additions & 1 deletion src/proto3Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import { Proto3DocumentSymbolProvider } from './proto3SymbolProvider';

export function activate(ctx: vscode.ExtensionContext): void {

const workspaceFolder = vscode.workspace.workspaceFolders[0];
ctx.subscriptions.push(vscode.languages.registerCompletionItemProvider(PROTO3_MODE, new Proto3CompletionItemProvider(), '.', '\"'));
ctx.subscriptions.push(vscode.languages.registerDefinitionProvider(PROTO3_MODE, new Proto3DefinitionProvider()));
ctx.subscriptions.push(vscode.languages.registerDefinitionProvider(PROTO3_MODE, new Proto3DefinitionProvider(workspaceFolder)));

const diagnosticProvider = new Proto3LanguageDiagnosticProvider();

Expand Down