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

added phpconfig.json with support for including/excluding files #181

Open
wants to merge 9 commits into
base: develop
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
9 changes: 9 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ Follow [@HvyIndustries](https://twitter.com/HvyIndustries) on Twitter for update

For the best development experience, make sure you have the PHP linter enabled in your user settings, and set it to run `onType` instead of `onSave`!

---

## What's new in v0.2.2 (latest release)

- Added new setting `crane.ignoredPaths` that gives users the ability to ignore files/folders for parsing _(workaround for parser crashing issue)_
- Added "what's new" section to readme to highlight new features/bug fixes

---

## Current Features

- Code-completion _(in progress, not quite 100% complete yet)_
Expand Down
21 changes: 17 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
"url": "https://hvy.io",
"email": "[email protected]"
},
"contributors": [
{
"name": "Ryan Naddy",
"email": "[email protected]",
"url": "http://ryannaddy.com"
}
],
"icon": "images/php-256.png",
"license": "MIT",
"version": "0.2.1",
"version": "0.2.2",
"publisher": "HvyIndustries",
"engines": {
"vscode": "^0.10.x"
Expand Down Expand Up @@ -43,7 +50,8 @@
"private": true,
"homepage": "https://hvy.io/crane",
"activationEvents": [
"onLanguage:php"
"onLanguage:php",
"workspaceContains:phpconfig.json"
],
"main": "./out/src/extension",
"contributes": {
Expand All @@ -70,6 +78,11 @@
"type": "string",
"default": "https://codeload.github.com/HvyIndustries/crane-php-stubs/zip/master",
"description": "The location of the PHP Stubs zip file that can be downloaded and unzipped for 3rd party library autocompletion"
},
"crane.ignoredPaths": {
"type": "array",
"default": [],
"description": "An array of files/folders that should be ignored by the parser. Glob patterns are accepted (eg. **/*bad.php)"
}
}
},
Expand Down Expand Up @@ -112,7 +125,7 @@
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"typescript": "^1.6.2",
"typescript": "^2.*.*",
"vscode": "^0.11.13"
},
"dependencies": {
Expand All @@ -123,4 +136,4 @@
"unzip": "^0.1.11",
"vscode-languageclient": "^1.1.0"
}
}
}
5 changes: 5 additions & 0 deletions client/phpTest/demo/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

class Test {

}
5 changes: 5 additions & 0 deletions client/phpTest/phpconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exclude": [
"demo"
]
}
2 changes: 1 addition & 1 deletion client/phpTest/simpletest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ class ParamClass
{
public $prop;
public $secondProp;
}
}
51 changes: 28 additions & 23 deletions client/src/crane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import {
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';
import { ThrottledDelayer } from './utils/async';
import { Cranefs } from './utils/Cranefs';
import { Debug } from './utils/Debug';
import { Config } from './utils/Config';
import Debug from './utils/Debug';
import Config from './utils/Config';
import PHPConfig from './utils/PHPConfig';

const exec = require('child_process').exec;
const util = require('util');
Expand All @@ -24,8 +25,7 @@ let craneSettings = workspace.getConfiguration("crane");

const cranefs: Cranefs = new Cranefs();
console.log(process.platform)
export default class Crane
{
export default class Crane {
public static langClient: LanguageClient;

private disposable: Disposable;
Expand All @@ -41,7 +41,7 @@ export default class Crane
let subscriptions: Disposable[] = [];

workspace.onDidChangeTextDocument((e) => this.onChangeTextHandler(e.document), null, subscriptions);
workspace.onDidCloseTextDocument((textDocument)=> { delete this.delayers[textDocument.uri.toString()]; }, null, subscriptions);
workspace.onDidCloseTextDocument((textDocument) => { delete this.delayers[textDocument.uri.toString()]; }, null, subscriptions);
workspace.onDidSaveTextDocument((document) => this.handleFileSave());

this.disposable = Disposable.from(...subscriptions);
Expand All @@ -56,8 +56,7 @@ export default class Crane
});
}

private checkVersion(): Thenable<boolean>
{
private checkVersion(): Thenable<boolean> {
var self = this;
Debug.info('Checking the current version of Crane');
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -140,25 +139,33 @@ export default class Crane
var types = Config.phpFileTypes;
Debug.info(`Watching these files: {${types.include.join(',')}}`);

var fsw: FileSystemWatcher = workspace.createFileSystemWatcher(`{${types.include.join(',')}}`);
var fsw: FileSystemWatcher = workspace.createFileSystemWatcher(`{${types.include.join(',')},**/phpconfig.json}`);
fsw.onDidChange(e => {
workspace.openTextDocument(e).then(document => {
if (document.languageId != 'php') return;
if (!['php', 'json'].indexOf(document.languageId)) return;
Debug.info('File Changed: ' + e.fsPath);
Crane.langClient.sendRequest({ method: 'buildObjectTreeForDocument' }, {
path: e.fsPath,
text: document.getText()
});
if (document.languageId == 'php') {
Crane.langClient.sendRequest({ method: 'buildObjectTreeForDocument' }, {
path: e.fsPath,
text: document.getText()
});
} else if (document.languageId == 'json') {
cranefs.processWorkspaceFiles(true);
}
});
});
fsw.onDidCreate(e => {
workspace.openTextDocument(e).then(document => {
if (document.languageId != 'php') return;
if (!['php', 'json'].indexOf(document.languageId)) return;
Debug.info('File Created: ' + e.fsPath);
Crane.langClient.sendRequest({ method: 'buildObjectTreeForDocument' }, {
path: e.fsPath,
text: document.getText()
});
if (document.languageId == 'php') {
Crane.langClient.sendRequest({ method: 'buildObjectTreeForDocument' }, {
path: e.fsPath,
text: document.getText()
});
} else if (document.languageId == 'json') {
cranefs.processWorkspaceFiles(true);
}
});
});
fsw.onDidDelete(e => {
Expand Down Expand Up @@ -277,21 +284,19 @@ export default class Crane
delayer.trigger(() => this.buildObjectTreeForDocument(textDocument));
}

private buildObjectTreeForDocument(document: TextDocument): Promise<void>
{
private buildObjectTreeForDocument(document: TextDocument): Promise<void> {
return new Promise<void>((resolve, reject) => {
var path = document.fileName;
var text = document.getText();
var projectDir = cranefs.getProjectDir();
var projectTree = cranefs.getTreePath();

var requestType: RequestType<any, any, any> = { method: "buildObjectTreeForDocument" };
Crane.langClient.sendRequest(requestType, { path, text, projectDir, projectTree }).then(() => resolve() );
Crane.langClient.sendRequest(requestType, { path, text, projectDir, projectTree }).then(() => resolve());
});
}

dispose()
{
dispose() {
this.disposable.dispose();
Crane.statusBarItem.dispose();
}
Expand Down
9 changes: 4 additions & 5 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, T

import Crane from "./crane";
import QualityOfLife from "./features/qualityOfLife";
import { Debug } from './utils/Debug';
import { Config } from './utils/Config';
import Debug from './utils/Debug';
import Config from './utils/Config';

export function activate(context: ExtensionContext)
{
export function activate(context: ExtensionContext) {
let qol: QualityOfLife = new QualityOfLife();

let serverModule = context.asAbsolutePath(path.join("server", "server.js"));
let debugOptions = { execArgv: ["--nolazy", "--debug=6004"] };

let serverOptions: ServerOptions = {
run : { module: serverModule, transport: TransportKind.ipc },
run: { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
}

Expand Down
9 changes: 7 additions & 2 deletions client/src/utils/Config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { workspace } from 'vscode';
import { Debug } from './Debug';
import Debug from './Debug';

var pkg = require('../../../package.json');

export class Config {
export default class Config {

public static craneSettings = workspace.getConfiguration("crane");

Expand Down Expand Up @@ -31,6 +31,11 @@ export class Config {
return Config.craneSettings ? Config.craneSettings.get<string>("phpstubsZipFile", "https://codeload.github.com/HvyIndustries/crane-php-stubs/zip/master") : "https://codeload.github.com/HvyIndustries/crane-php-stubs/zip/master";
}

public static get ignoredPaths(): Array<string> {
Config.reloadConfig();
return Config.craneSettings ? Config.craneSettings.get<Array<string>>("ignoredPaths", []) : [];
}

public static get version(): string {
return pkg.version.toString();
}
Expand Down
40 changes: 23 additions & 17 deletions client/src/utils/Cranefs.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { workspace, window } from 'vscode';
import { NotificationType, RequestType } from 'vscode-languageclient';
import Crane from '../crane';
import { Debug } from './Debug';
import { Config } from './Config';
import Debug from './Debug';
import Config from './Config';
import PHPConfig from './PHPConfig';

const crypto = require('crypto');
const fs = require('fs');
const crypto = require('crypto');
const fs = require('fs');
const fstream = require('fstream');
const http = require('https');
const unzip = require('unzip');
const util = require('util');
const mkdirp = require('mkdirp');
const rmrf = require('rimraf');
const http = require('https');
const unzip = require('unzip');
const util = require('util');
const mkdirp = require('mkdirp');
const rmrf = require('rimraf');

let craneSettings = workspace.getConfiguration("crane");

Expand All @@ -34,7 +35,7 @@ export class Cranefs {
return process.env.HOME + '/Library/Preferences/Crane';
}
if (process.platform == 'linux') {
return process.env.HOME + '/Crane';
return process.env.HOME + '/.Crane';
}
}

Expand Down Expand Up @@ -106,18 +107,18 @@ export class Cranefs {
Debug.error(util.inspect(error, false, null));
});
} else {
resolve({folderExists: false, folderCreated: false, path: null})
resolve({ folderExists: false, folderCreated: false, path: null })
}
});
}

public doesProjectTreeExist(): Promise<{exists:boolean, path:string}> {
public doesProjectTreeExist(): Promise<{ exists: boolean, path: string }> {
return new Promise((resolve, reject) => {
fs.stat(this.getTreePath(), (err, stat) => {
if (err === null) {
resolve({exists: true, path: this.getTreePath()});
resolve({ exists: true, path: this.getTreePath() });
} else {
resolve({exists: false, path: null});
resolve({ exists: false, path: null });
}
});
});
Expand All @@ -127,11 +128,16 @@ export class Cranefs {
if (workspace.rootPath == undefined) return;
var fileProcessCount = 0;

// Get PHP files from 'files.associations' to be processed
var files = Config.phpFileTypes;
PHPConfig.load();

// Get PHP files from 'phpconfig.json' to be processed
let files = PHPConfig.getFilePatterns();

// Exclude files ignored by the user
// files.exclude = files.exclude.concat(Config.ignoredPaths);

// Find all the php files to process
workspace.findFiles(`{${files.include.join(',')}}`, `{${files.exclude.join(',')}}`).then(files => {
workspace.findFiles(files.include, files.exclude).then(files => {
Debug.info(`Preparing to parse ${files.length} PHP source files...`);

fileProcessCount = files.length;
Expand Down
4 changes: 2 additions & 2 deletions client/src/utils/Debug.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { window, workspace, OutputChannel } from 'vscode';
import { Config } from './Config';
import Config from './Config';

const outputConsole = window.createOutputChannel("Crane Console");

export class Debug {
export default class Debug {

private static calls: number = 0;

Expand Down
26 changes: 26 additions & 0 deletions client/src/utils/PHPConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {workspace} from 'vscode';

export default class PHPConfig {

private static phpConfig: { files?: string[], exclude?: string[] } = {};

public static getFilePatterns(): { include: string, exclude: string } {
let pattern = { include: '**/*.php', exclude: '' };

if (this.phpConfig.files && this.phpConfig.files.length > 0) {
pattern.include = '{' + this.phpConfig.files.join(',') + '}';
} else if (this.phpConfig.exclude && this.phpConfig.exclude.length > 0) {
pattern.exclude = '{' + this.phpConfig.exclude.join(',') + '}';
}

return pattern;
}

public static load() {
try {
let file = workspace.rootPath + '/phpconfig.json';
this.phpConfig = require(file);
delete require.cache[require.resolve(file)];
} catch (e) { }
}
}
23 changes: 23 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install' ]
2 info using [email protected]
3 info using [email protected]
4 verbose readDependencies loading dependencies from C:\Users\rnaddy\Documents\vscode\projects\crane\package.json
5 error install Couldn't read dependencies
6 verbose stack Error: ENOENT: no such file or directory, open 'C:\Users\rnaddy\Documents\vscode\projects\crane\package.json'
6 verbose stack at Error (native)
7 verbose cwd C:\Users\rnaddy\Documents\vscode\projects\crane
8 error Windows_NT 10.0.14393
9 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
10 error node v4.4.7
11 error npm v2.15.8
12 error path C:\Users\rnaddy\Documents\vscode\projects\crane\package.json
13 error code ENOPACKAGEJSON
14 error errno -4058
15 error syscall open
16 error package.json ENOENT: no such file or directory, open 'C:\Users\rnaddy\Documents\vscode\projects\crane\package.json'
16 error package.json This is most likely not a problem with npm itself.
16 error package.json npm can't find a package.json file in your current directory.
17 verbose exit [ -4058, true ]
Loading