mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 01:29:04 +01:00
tsfmt - extensions/php
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import {CompletionItemProvider, CompletionItem, CompletionItemKind, CancellationToken, TextDocument, Position, Range, TextEdit} from 'vscode';
|
||||
import { CompletionItemProvider, CompletionItem, CompletionItemKind, CancellationToken, TextDocument, Position, Range, TextEdit } from 'vscode';
|
||||
import phpGlobals = require('./phpGlobals');
|
||||
|
||||
export default class PHPCompletionItemProvider implements CompletionItemProvider {
|
||||
@@ -14,19 +14,19 @@ export default class PHPCompletionItemProvider implements CompletionItemProvider
|
||||
|
||||
public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Promise<CompletionItem[]> {
|
||||
let result: CompletionItem[] = [];
|
||||
var range = document.getWordRangeAtPosition(position);
|
||||
var range = document.getWordRangeAtPosition(position);
|
||||
var prefix = range ? document.getText(range) : '';
|
||||
if (!range) {
|
||||
range = new Range(position, position);
|
||||
}
|
||||
|
||||
var added : any = {};
|
||||
var createNewProposal = function(kind: CompletionItemKind, name: string, entry: phpGlobals.IEntry) : CompletionItem {
|
||||
var proposal : CompletionItem = new CompletionItem(name);
|
||||
|
||||
var added: any = {};
|
||||
var createNewProposal = function (kind: CompletionItemKind, name: string, entry: phpGlobals.IEntry): CompletionItem {
|
||||
var proposal: CompletionItem = new CompletionItem(name);
|
||||
proposal.kind = kind;
|
||||
if (entry) {
|
||||
if (entry.description) {
|
||||
proposal.documentation= entry.description;
|
||||
proposal.documentation = entry.description;
|
||||
}
|
||||
if (entry.signature) {
|
||||
proposal.detail = entry.signature;
|
||||
@@ -35,14 +35,14 @@ export default class PHPCompletionItemProvider implements CompletionItemProvider
|
||||
return proposal;
|
||||
};
|
||||
|
||||
var matches = (name:string) => {
|
||||
var matches = (name: string) => {
|
||||
return prefix.length === 0 || name.length >= prefix.length && name.substr(0, prefix.length) === prefix;
|
||||
};
|
||||
|
||||
|
||||
if (matches('php') && range.start.character >= 2) {
|
||||
let twoBeforePosition = new Position(range.start.line, range.start.character - 2);
|
||||
let beforeWord = document.getText(new Range(twoBeforePosition, range.start));
|
||||
|
||||
|
||||
if (beforeWord === '<?') {
|
||||
let proposal = createNewProposal(CompletionItemKind.Class, '<?php', null);
|
||||
proposal.textEdit = new TextEdit(new Range(twoBeforePosition, position), '<?php');
|
||||
@@ -79,7 +79,7 @@ export default class PHPCompletionItemProvider implements CompletionItemProvider
|
||||
var text = document.getText();
|
||||
if (prefix[0] === '$') {
|
||||
var variableMatch = /\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/g;
|
||||
var match : RegExpExecArray = null;
|
||||
var match: RegExpExecArray = null;
|
||||
while (match = variableMatch.exec(text)) {
|
||||
var word = match[0];
|
||||
if (!added[word]) {
|
||||
@@ -89,7 +89,7 @@ export default class PHPCompletionItemProvider implements CompletionItemProvider
|
||||
}
|
||||
}
|
||||
var functionMatch = /function\s+([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*\(/g;
|
||||
var match : RegExpExecArray = null;
|
||||
var match: RegExpExecArray = null;
|
||||
while (match = functionMatch.exec(text)) {
|
||||
var word = match[1];
|
||||
if (!added[word]) {
|
||||
|
||||
Reference in New Issue
Block a user