From 564e6e12af5e427bc551a7c847e69f1e0dd380b0 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Thu, 25 Aug 2016 17:55:00 +0200 Subject: [PATCH] Initial Commit --- .editorconfig | 17 ++++++++++++++ .gitignore | 4 ++++ .travis.yml | 10 ++++++++ .vscode/launch.json | 36 ++++++++++++++++++++++++++++ .vscode/settings.json | 10 ++++++++ .vscode/tasks.json | 37 +++++++++++++++++++++++++++++ .vscodeignore | 9 +++++++ README.md | 24 +++++++++++++++++++ composer.json | 7 ++++++ package.json | 34 +++++++++++++++++++++++++++ src/extension.ts | 36 ++++++++++++++++++++++++++++ src/test/extension.test.ts | 22 +++++++++++++++++ src/test/index.ts | 22 +++++++++++++++++ tsconfig.json | 14 +++++++++++ tslint.json | 47 +++++++++++++++++++++++++++++++++++++ typings/node.d.ts | 1 + typings/vscode-typings.d.ts | 1 + 17 files changed, 331 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 .vscodeignore create mode 100644 README.md create mode 100644 composer.json create mode 100644 package.json create mode 100644 src/extension.ts create mode 100644 src/test/extension.test.ts create mode 100644 src/test/index.ts create mode 100644 tsconfig.json create mode 100644 tslint.json create mode 100644 typings/node.d.ts create mode 100644 typings/vscode-typings.d.ts diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b5f0c5d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ + +[*] +insert_final_newline = true +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 + +[*.{json,yml}] +indent_size = 2 + +[composer.json] +indent_size = 4 + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fa1889 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +out/ +node_modules/ +vendor/ +composer.lock diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c629c2d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: node_js + +node_js: + - '5.10.0' + +install: + - npm install + +script: + - npm run lint diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..a6fc4b2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,36 @@ +// A launch configuration that compiles the extension and then opens it inside a new window +{ + "version": "0.1.0", + "configurations": [ + { + "name": "Launch Extension", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceRoot}" + ], + "stopOnEntry": false, + "sourceMaps": true, + "outDir": "${workspaceRoot}/out" + }, + { + "name": "Launch Tests", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceRoot}", + "--extensionTestsPath=${workspaceRoot}/out/test" + ], + "stopOnEntry": false, + "sourceMaps": true, + "outDir": "${workspaceRoot}/out/test" + }, + { + "name": "Listen for XDebug", + "type": "php", + "request": "launch" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3f5aa9c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "files.exclude": { + "out": false // set this to true to hide the "out" folder with the compiled JS files + }, + "search.exclude": { + "out": true // set this to false to include "out" folder in search results + }, + "typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..5801050 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,37 @@ +// Available variables which can be used inside of strings. +// ${workspaceRoot}: the root folder of the team +// ${file}: the current opened file +// ${fileBasename}: the current opened file's basename +// ${fileDirname}: the current opened file's dirname +// ${fileExtname}: the current opened file's extension +// ${cwd}: the current working directory of the spawned process +// A task runner that calls a custom npm script that compiles the extension. +{ + "version": "0.1.0", + // we want to run npm + "command": "npm", + // the command is a shell script + "isShellCommand": true, + // show the output window only if unrecognized errors occur. + "showOutput": "silent", + // we run the custom script "compile" as defined in package.json + "args": [ + "run", + "--loglevel", + "silent" + ], + "tasks": [ + { + "taskName": "compile", + "isBuildCommand": true, + "problemMatcher": "$tsc" + }, + { + "taskName": "watch", + // The tsc compiler is started in watching mode + "isWatching": true, + // use the standard tsc in watch mode problem matcher to find compile problems in the output. + "problemMatcher": "$tsc-watch" + } + ] +} diff --git a/.vscodeignore b/.vscodeignore new file mode 100644 index 0000000..d09f859 --- /dev/null +++ b/.vscodeignore @@ -0,0 +1,9 @@ +.vscode/** +typings/** +out/test/** +test/** +src/** +**/*.map +.gitignore +tsconfig.json +tslint.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..a6a2012 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# PHP IntelliSense + +> **⚠ Work In Progress** + +[![Latest Release](https://vsmarketplacebadge.apphb.com/version-short/felixfbecker.php-intellisense.svg)](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense) [![Installs](https://vsmarketplacebadge.apphb.com/installs/felixfbecker.php-intellisense.svg)](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense) [![Rating](https://vsmarketplacebadge.apphb.com/rating-short/felixfbecker.php-intellisense.svg)](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense) [![Build Status](https://travis-ci.org/felixfbecker/vscode-php-intellisense.svg?branch=master)](https://travis-ci.org/felixfbecker/vscode-php-intellisense) [![Dependency Status](https://gemnasium.com/felixfbecker/vscode-php-intellisense.svg)](https://gemnasium.com/felixfbecker/vscode-php-intellisense) [![Gitter](https://badges.gitter.im/felixfbecker/vscode-php-intellisense.svg)](https://gitter.im/felixfbecker/vscode-php-intellisense?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + +Advanced PHP IntelliSense for Visual Studio Code. +In opposite to the included PHP IntelliSense and other PHP extensions, this uses an AST to parse the source code +instead of relying on naive regular expression parsing. + +## Features + - Find all symbols + +## Todo + - Autocompletion + - Rename + - Goto definition + - Format document + - Hover + - Follow composer autoloading + +## Contributing + +This is just the VS Code extension that spawns the actual language server. The language server itself is implemented purely in PHP [in its own repository](https://github.com/felixfbecker/php-language-server). diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..3153271 --- /dev/null +++ b/composer.json @@ -0,0 +1,7 @@ +{ + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "felixfbecker/language-server": "^2.0" + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..82720a1 --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "php-intellisense", + "displayName": "PHP IntelliSense", + "description": "Advanced Autocompletion and Refactoring support for PHP", + "publisher": "felixfbecker", + "author": "Felix Becker ", + "license": "ISC", + "private": true, + "version": "0.0.1", + "engines": { + "vscode": "^1.4.0" + }, + "categories": [ + "Languages" + ], + "activationEvents": [ + "onLanguage:php" + ], + "main": "./out/extension", + "scripts": { + "vscode:prepublish": "node ./node_modules/vscode/bin/compile", + "compile": "node ./node_modules/vscode/bin/compile -watch -p ./", + "postinstall": "node ./node_modules/vscode/bin/install", + "lint": "tslint -c tslint.json \"src/**/*.ts\"" + }, + "devDependencies": { + "tslint": "^3.15.1", + "typescript": "^1.8.10", + "vscode": "^0.11.17" + }, + "dependencies": { + "vscode-languageclient": "^2.4.2-next.10" + } +} diff --git a/src/extension.ts b/src/extension.ts new file mode 100644 index 0000000..c1c2728 --- /dev/null +++ b/src/extension.ts @@ -0,0 +1,36 @@ +'use strict'; + +import * as path from 'path'; + +import { ExtensionContext } from 'vscode'; +import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient'; + +export function activate(context: ExtensionContext) { + + // The server is implemented in PHP + const serverPath = context.asAbsolutePath(path.join('vendor', 'felixfbecker', 'language-server', 'bin', 'php-language-server.php')); + + const serverOptions: ServerOptions = { + command: 'php', + args: [serverPath] + }; + + // Options to control the language client + let clientOptions: LanguageClientOptions = { + // Register the server for php documents + documentSelector: ['php'] + // synchronize: { + // // Synchronize the setting section 'php' to the server + // configurationSection: 'php', + // // Notify the server about file changes to composer.json files contain in the workspace + // fileEvents: workspace.createFileSystemWatcher('**/composer.json') + // } + }; + + // Create the language client and start the client. + const disposable = new LanguageClient('PHP Language Client', serverOptions, clientOptions).start(); + + // Push the disposable to the context's subscriptions so that the + // client can be deactivated on extension deactivation + context.subscriptions.push(disposable); +} diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts new file mode 100644 index 0000000..cc88f6a --- /dev/null +++ b/src/test/extension.test.ts @@ -0,0 +1,22 @@ +// +// Note: This example test is leveraging the Mocha test framework. +// Please refer to their documentation on https://mochajs.org/ for help. +// + +// The module 'assert' provides assertion methods from node +import * as assert from 'assert'; + +// You can import and use all API from the 'vscode' module +// as well as import your extension to test it +// import * as vscode from 'vscode'; +// import * as myExtension from '../extension'; + +// Defines a Mocha test suite to group tests of similar kind together +suite('Extension Tests', () => { + + // Defines a Mocha unit test + test('Something 1', () => { + assert.equal(-1, [1, 2, 3].indexOf(5)); + assert.equal(-1, [1, 2, 3].indexOf(0)); + }); +}); diff --git a/src/test/index.ts b/src/test/index.ts new file mode 100644 index 0000000..a41876c --- /dev/null +++ b/src/test/index.ts @@ -0,0 +1,22 @@ +// +// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING +// +// This file is providing the test runner to use when running extension tests. +// By default the test runner in use is Mocha based. +// +// You can provide your own test runner if you want to override it by exporting +// a function run(testRoot: string, clb: (error:Error) => void) that the extension +// host can call to run the tests. The test runner is expected to use console.log +// to report the results back to the caller. When the tests are finished, return +// a possible error to the callback or null if none. + +const testRunner = require('vscode/lib/testrunner'); + +// You can directly control Mocha options by uncommenting the following lines +// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info +testRunner.configure({ + ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.) + useColors: true // colored output from test results +}); + +module.exports = testRunner; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..7076a94 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "ES5", + "module": "commonjs", + "moduleResolution": "node", + "outDir": "out", + "noLib": true, + "sourceMap": true, + "rootDir": "src" + }, + "exclude": [ + "node_modules" + ] +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..c12f024 --- /dev/null +++ b/tslint.json @@ -0,0 +1,47 @@ +{ + "rules": { + "class-name": true, + "comment-format": [true, "check-space"], + "indent": [true, "spaces"], + "no-duplicate-variable": true, + "no-eval": true, + "no-internal-module": true, + "no-trailing-whitespace": true, + "no-var-keyword": true, + "one-line": [true, "check-catch", "check-finally", "check-else", "check-open-brace", "check-whitespace"], + "quotemark": [true, "single"], + "semicolon": [true, "always"], + "triple-equals": [true, "allow-null-check"], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + }, + { + "call-signature": "onespace", + "index-signature": "onespace", + "parameter": "onespace", + "property-declaration": "onespace", + "variable-declaration": "onespace" + } + ], + "variable-name": [true, "ban-keywords"], + "whitespace": [true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type"], + "jsdoc-format": true, + "no-consecutive-blank-lines": true, + "one-variable-per-declaration": [true, "ignore-for-loop"], + "curly": true, + "no-empty": true, + "no-duplicate-key": true, + "no-unreachable": true, + "no-unused-expression": true, + "no-unused-variable": [true], + "eofline": true, + "trailing-comma": [true, {"singleline": "never", "multiline": "never"}], + "align": [true, "parameters", "statements"] + } +} diff --git a/typings/node.d.ts b/typings/node.d.ts new file mode 100644 index 0000000..5ed7730 --- /dev/null +++ b/typings/node.d.ts @@ -0,0 +1 @@ +/// \ No newline at end of file diff --git a/typings/vscode-typings.d.ts b/typings/vscode-typings.d.ts new file mode 100644 index 0000000..5590dc8 --- /dev/null +++ b/typings/vscode-typings.d.ts @@ -0,0 +1 @@ +///