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

Commit

Permalink
Merge pull request #263 from HvyIndustries/feature/document-symbol-pr…
Browse files Browse the repository at this point in the history
…ovider

v0.3.3 release
  • Loading branch information
nevadascout authored Mar 13, 2017
2 parents cc9dc9b + 01d0c45 commit 5d16537
Show file tree
Hide file tree
Showing 14 changed files with 671 additions and 214 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ You can also set `php.suggest.basic` to `false` to disable VS Code's built-in ph

---

## What's new in v0.3.2 (latest release)
## What's new in v0.3.3 (latest release)
- Document symbol provider - view top level symbols in the current file
- Workspace symbol provider - view top level symbols throughout the workspace
- Performance improvements

## What's new in v0.3.2
- **Added go to definition on classes, traits & interfaces**
- Fix several bugs introduced in v0.3.1
- Namespace insert text should be prefixed with a backslash _(Thanks @TheColorRed for pointing out this mistake!)_
Expand Down Expand Up @@ -60,14 +65,14 @@ You can also set `php.suggest.basic` to `false` to disable VS Code's built-in ph
- Optionally for built-in PHP functions and classes (such as PDO)
- **Go to definition** on classes, interfaces and traits
- Peek definition on classes, interfaces and traits
- Document & workspace symbol providers

## Planned Features:

- Find references
- Signature provider to show method parameter suggestions
- Hover provider to show information about symbol under the cursor
- Full go-to/Peek definition on variables, methods, properties, etc
- List symbols
- PhpDoc support (both for reading and writing documentation)

## User Feedback
Expand Down
7 changes: 6 additions & 1 deletion client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# v0.3.2 (latest release)
# v0.3.3 (latest release)
- Document symbol provider - view top level symbols in the current file
- Workspace symbol provider - view top level symbols throughout the workspace
- Performance improvements

# v0.3.2
- **Added go to definition on classes, traits & interfaces**
- Fix several bugs introduced in v0.3.1
- Namespace insert text should be prefixed with a backslash _(Thanks @TheColorRed for pointing out this mistake!)_
Expand Down
9 changes: 7 additions & 2 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ You can also set `php.suggest.basic` to `false` to disable VS Code's built-in ph

---

## What's new in v0.3.2 (latest release)
## What's new in v0.3.3 (latest release)
- Document symbol provider - view top level symbols in the current file
- Workspace symbol provider - view top level symbols throughout the workspace
- Performance improvements

## What's new in v0.3.2
- **Added go to definition on classes, traits & interfaces**
- Fix several bugs introduced in v0.3.1
- Namespace insert text should be prefixed with a backslash _(Thanks @TheColorRed for pointing out this mistake!)_
Expand Down Expand Up @@ -60,14 +65,14 @@ You can also set `php.suggest.basic` to `false` to disable VS Code's built-in ph
- Optionally for built-in PHP functions and classes (such as PDO)
- **Go to definition** on classes, interfaces and traits
- Peek definition on classes, interfaces and traits
- Document & workspace symbol providers

## Planned Features:

- Find references
- Signature provider to show method parameter suggestions
- Hover provider to show information about symbol under the cursor
- Full go-to/Peek definition on variables, methods, properties, etc
- List symbols
- PhpDoc support (both for reading and writing documentation)

## User Feedback
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"icon": "images/php-256.png",
"license": "MIT",
"version": "0.3.2",
"version": "0.3.3",
"publisher": "HvyIndustries",
"engines": {
"vscode": "^1.8.0"
Expand Down
71 changes: 71 additions & 0 deletions client/phpTest/demo/documentSymbol.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Hvy\CraneDemo\MySubNamespace
{
class MyClass implements MyInterface
{
public $publicProperty;
private $privateProperty;

CONST MYCONST = "";

public function __construct()
{

}

public function publicMethod($param1)
{

}

private function privateMethod()
{

}
}

trait MyTrait
{
public $publicProperty;
private $privateProperty;

public function __construct()
{

}

public function publicMethod($param1)
{

}

private function privateMethod()
{

}
}

interface MyInterface
{
public function publicMethod($param1);
}
}

namespace myOtherNamespace
{
class MyClass
{

}

trait MyTrait
{

}

interface MyInterface
{

}
}
64 changes: 42 additions & 22 deletions client/src/features/qualityOfLife.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,85 @@
"use strict";

import * as vscode from 'vscode';
import { ThrottledDelayer } from "../utils/async";

export default class QualityOfLife
{
private disposable: vscode.Disposable;

private delayers: { [key: string]: ThrottledDelayer<void> };
private todoCommentDecoration: vscode.TextEditorDecorationType;

constructor()
{
this.delayers = Object.create(null);

let subscriptions: vscode.Disposable[] = [];
vscode.workspace.onDidChangeTextDocument((e) => this.onChangeTextHandler(e.document), null, subscriptions);
vscode.workspace.onDidCloseTextDocument((textDocument)=> { delete this.delayers[textDocument.uri.toString()]; }, null, subscriptions);
vscode.window.onDidChangeActiveTextEditor(editor => { this.onChangeEditorHandler(editor) }, null, subscriptions);
this.disposable = vscode.Disposable.from(...subscriptions);

this.todoCommentDecoration = vscode.window.createTextEditorDecorationType({
overviewRulerLane: vscode.OverviewRulerLane.Right,
color: "rgba(91, 199, 235, 1)",
overviewRulerColor: 'rgba(144, 195, 212, 0.7)' // Light Blue
overviewRulerColor: 'rgba(144, 195, 212, 0.7)', // Light Blue
isWholeLine: false,
backgroundColor: 'rgba(91, 199, 235, 0.1)'
});

this.styleTodoComments();
}

private onChangeEditorHandler(editor: vscode.TextEditor)
{
// Only process PHP files
if (editor.document.languageId != "php") return;

this.styleTodoComments();
}

private onChangeTextHandler(textDocument: vscode.TextDocument)
{
// Style todo comments as blue (+ add marker in sidebar)
this.styleTodoComments();
private onChangeTextHandler(textDocument: vscode.TextDocument) {
// Only process PHP files
if (textDocument.languageId != "php") return;

let key = textDocument.uri.toString();
let delayer = this.delayers[key];

if (!delayer) {
delayer = new ThrottledDelayer<void>(200);
this.delayers[key] = delayer;
}

delayer.trigger(() => this.styleTodoComments());
}

private styleTodoComments()
{
var editor = vscode.window.activeTextEditor;
if (editor == null) return;
return new Promise<void>((resolve, reject) => {
var editor = vscode.window.activeTextEditor;
if (editor == null) return;

// Reset any existing todo style decorations
editor.setDecorations(this.todoCommentDecoration, []);
// Reset any existing todo style decorations
editor.setDecorations(this.todoCommentDecoration, []);

var matchedLines = [];
var matchedLines = [];

// Parse document searching for regex match
for (var i = 0; i < editor.document.lineCount; i++) {
var line = editor.document.lineAt(i);
// Parse document searching for regex match
for (var i = 0; i < Math.min(3000, editor.document.lineCount); i++) {
var line = editor.document.lineAt(i);

var regex = /(\/\/|#)(\stodo|todo)/ig;
var result = regex.exec(line.text);
var regex = /(\/\/|#)(\stodo|todo)/ig;
var result = regex.exec(line.text);

if (result != null)
{
var lineOption = { range: new vscode.Range(i, result.index, i, 99999) };
matchedLines.push(lineOption);
if (result != null) {
var lineOption = { range: new vscode.Range(i, result.index, i, line.range.end.character) };
matchedLines.push(lineOption);
}
}
}

editor.setDecorations(this.todoCommentDecoration, matchedLines);
editor.setDecorations(this.todoCommentDecoration, matchedLines);
resolve();
});
}

dispose()
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "crane-lang-server",
"description": "The language server for Crane",
"version": "1.1.2",
"version": "1.1.3",
"author": "HVY Industries",
"license": "MIT",
"engines": {
Expand Down
10 changes: 9 additions & 1 deletion server/src/hvy/treeBuilderV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class TreeBuilderV2
} else {
switch (branch.kind) {
case "namespace":
tree.namespaces.push(new NamespaceNode(branch.name));
this.buildNamespaceDeclaration(branch, tree);
this.processBranch(branch.children, tree, branch);
break;

Expand Down Expand Up @@ -145,6 +145,14 @@ export class TreeBuilderV2
}
}

private buildNamespaceDeclaration(branch, context: FileNode)
{
let namespace = new NamespaceNode(branch.name);
namespace.startPos = this.buildPosition(branch.loc.start);
namespace.endPos = this.buildPosition(branch.loc.end);
context.namespaces.push(namespace);
}

private buildfileInclude(branch, context: FileNode)
{
switch (branch.target.kind) {
Expand Down
29 changes: 19 additions & 10 deletions server/src/providers/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ export class DefinitionProvider

var toReturn = [];

this.workspaceTree.forEach(filenode => {
filenode.classes.forEach((classNode) => {
for (var i = 0, l = this.workspaceTree.length; i < l; i++) {
var filenode = this.workspaceTree[i];

for (var j = 0, sl = filenode.classes.length; j < sl; j++) {
var classNode = filenode.classes[j];
if (
classNode.name.toLowerCase() == rawClassname.toLowerCase()
&& classNode.namespace == namespace
Expand All @@ -132,8 +135,10 @@ export class DefinitionProvider

toReturn.push(nodeInfo);
}
});
filenode.traits.forEach((traitNode) => {
}

for (var j = 0, sl = filenode.traits.length; j < sl; j++) {
var traitNode = filenode.traits[j];
if (
traitNode.name.toLowerCase() == rawClassname.toLowerCase()
&& traitNode.namespace == namespace
Expand All @@ -145,8 +150,10 @@ export class DefinitionProvider

toReturn.push(nodeInfo);
}
});
filenode.interfaces.forEach((interfaceNode) => {
}

for (var j = 0, sl = filenode.interfaces.length; j < sl; j++) {
var interfaceNode = filenode.interfaces[j];
if (
interfaceNode.name.toLowerCase() == rawClassname.toLowerCase()
&& interfaceNode.namespace == namespace
Expand All @@ -158,8 +165,8 @@ export class DefinitionProvider

toReturn.push(nodeInfo);
}
});
});
}
}

return toReturn;
}
Expand All @@ -168,7 +175,9 @@ export class DefinitionProvider
{
var toReturn: Location[] = [];

nodes.forEach(item => {
for (var i = 0, l = nodes.length; i < l; i++) {
var item = nodes[i];

let location: Location = {
uri: Files.getUriFromPath(item.path),
range: {
Expand All @@ -184,7 +193,7 @@ export class DefinitionProvider
};

toReturn.push(location);
});
}

return toReturn;
}
Expand Down
Loading

0 comments on commit 5d16537

Please sign in to comment.