Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ShyykoSerhiy committed Jan 22, 2017
0 parents commit 55c61ce
Show file tree
Hide file tree
Showing 16 changed files with 2,751 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
node_modules
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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,
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
"preLaunchTask": "npm"
},
{
"name": "Launch Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
"preLaunchTask": "npm"
}
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
30 changes: 30 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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", "compile", "--loglevel", "silent"],

// 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"
}
9 changes: 9 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vscode/**
.vscode-test/**
out/test/**
test/**
src/**
**/*.map
.gitignore
tsconfig.json
vsc-extension-quickstart.md
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change Log
All notable changes to the "sockscode-vscode" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]
- Initial release
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# sockscode-vscode README

This is the README for your extension "sockscode-vscode". After writing up a brief description, we recommend including the following sections.

## Features

Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.

For example if there is an image subfolder under your extension project workspace:

\!\[feature X\]\(images/feature-x.png\)

> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
## Requirements

If you have any requirements or dependencies, add a section describing those and how to install and configure them.

## Extension Settings

Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.

For example:

This extension contributes the following settings:

* `myExtension.enable`: enable/disable this extension
* `myExtension.thing`: set to `blah` to do something

## Known Issues

Calling out known issues can help limit users opening duplicate issues against your extension.

## Release Notes

Users appreciate release notes as you update your extension.

### 1.0.0

Initial release of ...

### 1.0.1

Fixed issue #.

### 1.1.0

Added features X, Y, and Z.

-----------------------------------------------------------------------------------------------------------

## Working with Markdown

**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:

* Split the editor (`Cmd+\` on OSX or `Ctrl+\` on Windows and Linux)
* Toggle preview (`Shift+CMD+V` on OSX or `Shift+Ctrl+V` on Windows and Linux)
* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (OSX) to see a list of Markdown snippets

### For more information

* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)

**Enjoy!**
64 changes: 64 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "sockscode-vscode",
"displayName": "sockscode-vscode",
"description": "",
"version": "0.0.1",
"publisher": "shyykoserhiy",
"engines": {
"vscode": "^1.5.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:sockscode.createRoom",
"onCommand:sockscode.connect"
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"command": "sockscode.createRoom",
"title": "Sockscode create a new room."
},
{
"command": "sockscode.connect",
"title": "Sockscode connect to a room."
},
{
"command": "sockscode.disconnect",
"title": "Sockscode disconect."
}
],
"configuration": {
"type": "object",
"title": "sockscode-vscode configuration",
"properties": {
"sockscode.server": {
"type": "string",
"default": "https://sockscode.azurewebsites.net",
"description": "Specifies sockscode compatible server url."
}
}
}
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
},
"dependencies": {
"socket.io": "^1.7.2",
"socket.io-client": "^1.7.2"
},
"devDependencies": {
"typescript": "^2.0.3",
"vscode": "^1.0.0",
"mocha": "^2.3.3",
"@types/node": "^6.0.40",
"@types/mocha": "^2.2.32",
"@types/socket.io": "^1.4.27",
"@types/socket.io-client": "^1.4.29"
}
}
9 changes: 9 additions & 0 deletions src/config/Config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { workspace } from 'vscode';

export function getConfig() {
return workspace.getConfiguration('sockscode');
}

export function getSockscodeServerUrl(): string {
return getConfig().get<string>('server');
}
116 changes: 116 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
'use strict';
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import { Disposable, ExtensionContext, window, commands, TextEditor, workspace, TextDocumentChangeEvent, Range } from 'vscode';
import * as socketio from 'socket.io-client';
import { SocketIoCodeService } from './service/SocketIoCodeService';

class SocksCodeController {
private _socketIoCodeService: SocketIoCodeService;
private _roomUuid: string;
private _disposable: Disposable;
/**
* We store this value to ensure to not send a change code socket event
* if the text in change is the same as we've received in socket.
*/
private _prevRemoteText: string;

constructor() {
this._socketIoCodeService = SocketIoCodeService.createInstance();
this._socketIoCodeService.onCodeChange((data) => {
const editor = window.activeTextEditor;
if (!editor) {
return;
}
editor.edit((editBuilder) => {
//FIXME change this to actual change tracking
//it will lesser load on server make things faster for big files!
// this uglines is only for POC
this._prevRemoteText = data.code;
editBuilder.replace(new Range(0, 0, 99999, 0), data.code);
});
});
this._socketIoCodeService.onCreateRoom((_roomUuid) => {
this._roomUuid = _roomUuid;
window.showInformationMessage(`Room created. Room uuid :${this._roomUuid}`);
});
//vscode event subscriptions
let subscriptions: Disposable[] = [];
window.onDidChangeActiveTextEditor(this._onDidChangeActiveTextEditor, this, subscriptions);
workspace.onDidChangeTextDocument(this._onDidChangeTextDocument, this, subscriptions);
// create a combined disposable from both event subscriptions
this._disposable = Disposable.from(...subscriptions);
}

public createRoom() {
this._socketIoCodeService.createRoom();
}

public dispose() {
this._socketIoCodeService.close();
}

private _onDidChangeActiveTextEditor() {
this._onCodeChange();
}

private _onDidChangeTextDocument(textDocumentChangeEvent: TextDocumentChangeEvent) {
//fixme?
this._onCodeChange();
}

private showRoom() {
window.showInformationMessage(`Your room uuid :${this._roomUuid}`);
}

private _onCodeChange() {
const editor = window.activeTextEditor;
if (!editor) {
return;
}
const text = editor.document.getText();
if (text === this._prevRemoteText) {
this._prevRemoteText = null;
return;
}
this._socketIoCodeService.changeCode(text);
}
}
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: ExtensionContext) {


// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "sockscode-vscode" is now active!');
let socksCodeController: SocksCodeController;

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposableComands = [
commands.registerCommand('sockscode.createRoom', () => {
if (!socksCodeController) {
socksCodeController = new SocksCodeController();
socksCodeController.createRoom();
}
}),
commands.registerCommand('sockscode.connect', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
window.showInformationMessage('connect!');
}),
commands.registerCommand('sockscode.disconnect', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
window.showInformationMessage('disconnect!');
})
];

context.subscriptions.push(...disposableComands);
}

// this method is called when your extension is deactivated
export function deactivate() {
}
Loading

0 comments on commit 55c61ce

Please sign in to comment.