typeprof 0.21.2 → 0.21.3

Sign up to get free protection for your applications and to get access to all the features.
data/vscode/package.json DELETED
@@ -1,71 +0,0 @@
1
- {
2
- "name": "ruby-typeprof",
3
- "displayName": "Ruby TypeProf",
4
- "version": "0.20.1",
5
- "publisher": "mame",
6
- "author": {
7
- "name": "Yusuke Endoh"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/ruby/typeprof/tree/master/vscode"
12
- },
13
- "license": "MIT",
14
- "categories": [
15
- "Programming Languages"
16
- ],
17
- "keywords": [
18
- "Ruby",
19
- "language server"
20
- ],
21
- "engines": {
22
- "vscode": "^1.54.0"
23
- },
24
- "extensionKind": [
25
- "workspace"
26
- ],
27
- "activationEvents": [
28
- "onLanguage:ruby"
29
- ],
30
- "contributes": {
31
- "commands": [
32
- {
33
- "command": "typeprof.restart",
34
- "title": "Restart",
35
- "category": "TypeProf"
36
- }
37
- ],
38
- "configuration": [
39
- {
40
- "title": "Ruby TypeProf",
41
- "properties": {
42
- "typeprof.server.path": {
43
- "type": [
44
- "null",
45
- "string"
46
- ],
47
- "default": null,
48
- "description": "Path to typeprof executable. (e.g. /usr/local/bin/bundle)"
49
- }
50
- }
51
- }
52
- ]
53
- },
54
- "main": "./out/src/extension",
55
- "scripts": {
56
- "vscode:prepublish": "tsc -p ./",
57
- "compile": "tsc -watch -p ./",
58
- "postinstall": "node ./node_modules/vscode/bin/install",
59
- "test": "node ./node_modules/vscode/bin/test",
60
- "package": "vsce package"
61
- },
62
- "devDependencies": {
63
- "@types/node": "^14.14.37",
64
- "typescript": "^4.2.3",
65
- "vsce": "^1.103.1",
66
- "vscode": "^1.1.37"
67
- },
68
- "dependencies": {
69
- "vscode-languageclient": "^7.0.0"
70
- }
71
- }
@@ -1,24 +0,0 @@
1
- class C
2
- def initialize
3
- end
4
-
5
- def get_foo
6
- :Foo_foo
7
- end
8
-
9
- def get_bar
10
- :Foo_bar
11
- end
12
- end
13
-
14
- class D
15
- def get_foo
16
- :Foo2_foo
17
- end
18
- end
19
-
20
- C.new.get_foo
21
- C.new.get_bar
22
-
23
- x = rand < 0.5 ? C.new : D.new
24
- x.get_foo
@@ -1,302 +0,0 @@
1
- "use strict";
2
-
3
- import * as vscode from "vscode";
4
- import {
5
- LanguageClient,
6
- LanguageClientOptions,
7
- ServerOptions,
8
- } from "vscode-languageclient/node";
9
- import * as net from "net";
10
- import * as child_process from "child_process";
11
- import { existsSync } from "fs";
12
-
13
- interface Invoking {
14
- kind: "invoking";
15
- workspaceFolder: vscode.WorkspaceFolder;
16
- process: child_process.ChildProcessWithoutNullStreams;
17
- }
18
- interface Running {
19
- kind: "running";
20
- workspaceFolder: vscode.WorkspaceFolder;
21
- client: LanguageClient;
22
- }
23
- type State = Invoking | Running;
24
-
25
- const CONFIGURATION_ROOT_SECTION = "typeprof";
26
-
27
- function addToggleButton(context: vscode.ExtensionContext) {
28
- let statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
29
- statusBarItem.command = "typeprof.toggle";
30
- statusBarItem.text = "TypeProf $(eye)";
31
- statusBarItem.show();
32
-
33
- const disposable = vscode.commands.registerCommand("typeprof.toggle",
34
- (arg0: any, arg1: any, arg2: any, arg3: any) => {
35
- if (statusBarItem.text == "TypeProf $(eye)") {
36
- statusBarItem.text = "TypeProf $(eye-closed)";
37
- vscode.commands.executeCommand("typeprof.disableSignature");
38
- }
39
- else {
40
- statusBarItem.text = "TypeProf $(eye)";
41
- vscode.commands.executeCommand("typeprof.enableSignature");
42
- }
43
- }
44
- );
45
-
46
- context.subscriptions.push(disposable);
47
- }
48
-
49
- function addJumpToRBS(context: vscode.ExtensionContext) {
50
- const disposable = vscode.commands.registerCommand("typeprof.jumpToRBS",
51
- (arg0: any, arg1: any, arg2: any, arg3: any) => {
52
- const uri0 = vscode.Uri.parse(arg0);
53
- const pos0 = new vscode.Position(arg1.line, arg1.character);
54
- const uri1 = vscode.Uri.parse(arg2);
55
- const pos1 = new vscode.Position(arg3.start.line, arg3.start.character);
56
- const pos2 = new vscode.Position(arg3.end.line, arg3.end.character);
57
- const range = new vscode.Range(pos1, pos2);
58
- const loc = new vscode.Location(uri1, range);
59
- vscode.commands.executeCommand("editor.action.peekLocations", uri0, pos0, [loc], "peek");
60
- }
61
- );
62
-
63
- context.subscriptions.push(disposable);
64
- }
65
-
66
- function executeTypeProf(folder: vscode.WorkspaceFolder, arg: String): child_process.ChildProcessWithoutNullStreams {
67
- const configuration = vscode.workspace.getConfiguration(CONFIGURATION_ROOT_SECTION);
68
- const customServerPath = configuration.get<string | null>("server.path");
69
- const cwd = folder.uri.fsPath;
70
-
71
- let cmd: string;
72
- if (existsSync(`${cwd}/bin/typeprof`)) {
73
- cmd = "./bin/typeprof";
74
- }
75
- else if (customServerPath) {
76
- cmd = customServerPath;
77
- }
78
- else if (existsSync(`${cwd}/Gemfile`)) {
79
- cmd = "bundle exec typeprof";
80
- }
81
- else {
82
- cmd = "typeprof";
83
- }
84
- cmd = cmd + " " + arg;
85
-
86
- const shell = process.env.SHELL;
87
- let typeprof: child_process.ChildProcessWithoutNullStreams;
88
- if (shell && (shell.endsWith("bash") || shell.endsWith("zsh") || shell.endsWith("fish"))) {
89
- typeprof = child_process.spawn(shell, ["-c", "-l", cmd], { cwd });
90
- }
91
- else if (process.platform === "win32") {
92
- typeprof = child_process.spawn("C:\\Windows\\System32\\cmd.exe", ["/c", cmd], { cwd });
93
- }
94
- else {
95
- typeprof = child_process.spawn(cmd, { cwd });
96
- }
97
-
98
- return typeprof;
99
- }
100
-
101
- function getTypeProfVersion(folder: vscode.WorkspaceFolder, outputChannel: vscode.OutputChannel, callback: (version: string) => void): child_process.ChildProcessWithoutNullStreams {
102
- const typeprof = executeTypeProf(folder, "--version");
103
- let output = "";
104
-
105
- const log = (msg: string) => {
106
- outputChannel.appendLine("[vscode] " + msg);
107
- console.info(msg);
108
- };
109
-
110
- typeprof.stdout?.on("data", out => { output += out; });
111
- typeprof.stderr?.on("data", (out: Buffer) => {
112
- const str = ("" + out).trim();
113
- for (const line of str.split("\n")) {
114
- log("stderr: " + line);
115
- }
116
- });
117
- typeprof.on("error", e => {
118
- log(`typeprof is not supported for this folder: ${folder}`);
119
- log(`because: ${e}`);
120
- });
121
- typeprof.on("exit", (code) => {
122
- if (code == 0) {
123
- const str = output.trim();
124
- log(`typeprof version: ${str}`)
125
- const version = /^typeprof (\d+).(\d+).(\d+)$/.exec(str);
126
- if (version) {
127
- const major = Number(version[1]);
128
- const minor = Number(version[2]);
129
- const _teeny = Number(version[3]);
130
- if (major >= 1 || (major == 0 && minor >= 20)) {
131
- callback(str);
132
- }
133
- else {
134
- log(`typeprof version ${str} is too old; please use 0.20.0 or later for IDE feature`);
135
- }
136
- }
137
- else {
138
- log(`typeprof --version showed unknown message`);
139
- }
140
- }
141
- else {
142
- log(`failed to invoke typeprof: error code ${code}`);
143
- }
144
- typeprof.kill()
145
- });
146
- return typeprof;
147
- }
148
-
149
- function getTypeProfStream(folder: vscode.WorkspaceFolder, error: (msg: string) => void):
150
- Promise<{ host: string; port: number; pid: number; stop: () => void }>
151
- {
152
- return new Promise((resolve, reject) => {
153
- const typeprof = executeTypeProf(folder, "--lsp");
154
-
155
- let buffer = "";
156
- typeprof.stdout.on("data", (data) => {
157
- buffer += data;
158
- try {
159
- const json = JSON.parse(data);
160
- json["stop"] = () => typeprof.kill("SIGINT");
161
- resolve(json);
162
- } catch (err) {}
163
- });
164
-
165
- let err = "";
166
- typeprof.stderr.on("data", (data) => {
167
- err += data;
168
- while (true) {
169
- const i = err.indexOf("\n");
170
- if (i < 0) break;
171
- error(err.slice(0, i));
172
- err = err.slice(i + 1);
173
- }
174
- });
175
-
176
- typeprof.on("exit", (code) => reject(`error code ${code}`));
177
- });
178
- }
179
-
180
- function invokeTypeProf(folder: vscode.WorkspaceFolder, outputChannel: vscode.OutputChannel): LanguageClient {
181
- let client: LanguageClient;
182
-
183
- const reportError = (msg: string) => client.info(msg);
184
-
185
- const serverOptions: ServerOptions = async () => {
186
- const { host, port, stop } = await getTypeProfStream(folder, reportError);
187
- const socket: net.Socket = net.createConnection(port, host);
188
- socket.on("close", (_had_error) => stop());
189
-
190
- return {
191
- reader: socket,
192
- writer: socket,
193
- };
194
- };
195
-
196
- const clientOptions: LanguageClientOptions = {
197
- documentSelector: [
198
- { scheme: "file", language: "ruby" },
199
- { scheme: "file", language: "rbs" },
200
- ],
201
- outputChannel,
202
- synchronize: {
203
- fileEvents:
204
- vscode.workspace.createFileSystemWatcher("{**/*.rb,**/*.rbs}"),
205
- },
206
- };
207
-
208
- client = new LanguageClient("Ruby TypeProf", serverOptions, clientOptions);
209
-
210
- return client;
211
- }
212
-
213
- const clientSessions: Map<vscode.WorkspaceFolder, State> = new Map();
214
-
215
- function startTypeProf(folder: vscode.WorkspaceFolder) {
216
- const outputChannel = vscode.window.createOutputChannel("Ruby TypeProf");
217
- const showStatus = (msg: string) => {
218
- outputChannel.appendLine("[vscode] " + msg);
219
- vscode.window.setStatusBarMessage(msg, 3000);
220
- }
221
- outputChannel.appendLine("[vscode] Try to start TypeProf for IDE");
222
-
223
- const typeprof = getTypeProfVersion(folder, outputChannel, (version) => {
224
- if (!version) {
225
- showStatus(`Ruby TypeProf is not configured; Try to add "gem 'typeprof'" to Gemfile`);
226
- clientSessions.delete(folder);
227
- return;
228
- }
229
- showStatus(`Starting Ruby TypeProf (${version})...`);
230
- const client = invokeTypeProf(folder, outputChannel);
231
- client.onReady()
232
- .then(() => {
233
- showStatus("Ruby TypeProf is running");
234
- })
235
- .catch((e: any) => {
236
- showStatus(`Failed to start Ruby TypeProf: ${e}`);
237
- });
238
- client.start();
239
- clientSessions.set(folder, { kind: "running", workspaceFolder: folder, client });
240
- });
241
-
242
- clientSessions.set(folder, { kind: "invoking", workspaceFolder: folder, process: typeprof });
243
- }
244
-
245
- function stopTypeProf(state: State) {
246
- switch (state.kind) {
247
- case "invoking":
248
- state.process.kill();
249
-
250
- break;
251
- case "running":
252
- state.client.stop();
253
- break;
254
- }
255
- clientSessions.delete(state.workspaceFolder);
256
- }
257
-
258
- function restartTypeProf() {
259
- vscode.workspace.workspaceFolders?.forEach((folder) => {
260
- let state = clientSessions.get(folder);
261
- if (state) stopTypeProf(state);
262
- startTypeProf(folder);
263
- });
264
- }
265
-
266
- function ensureTypeProf() {
267
- if (!vscode.workspace.workspaceFolders) return;
268
-
269
- const activeFolders = new Set(vscode.workspace.workspaceFolders);
270
-
271
- clientSessions.forEach((state) => {
272
- if (!activeFolders.has(state.workspaceFolder)) {
273
- stopTypeProf(state);
274
- }
275
- });
276
-
277
- activeFolders.forEach((folder) => {
278
- if (folder.uri.scheme === "file" && !clientSessions.has(folder)) {
279
- startTypeProf(folder);
280
- }
281
- });
282
- }
283
-
284
- function addRestartCommand(context: vscode.ExtensionContext) {
285
- const disposable = vscode.commands.registerCommand("typeprof.restart", () => {
286
- restartTypeProf();
287
- });
288
- context.subscriptions.push(disposable);
289
- }
290
-
291
- export function activate(context: vscode.ExtensionContext) {
292
- addToggleButton(context);
293
- addJumpToRBS(context);
294
- addRestartCommand(context)
295
- ensureTypeProf();
296
- }
297
-
298
- export function deactivate() {
299
- clientSessions.forEach((state) => {
300
- stopTypeProf(state);
301
- });
302
- }
data/vscode/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "target": "es6",
5
- "outDir": "out",
6
- "lib": ["es6"],
7
- "sourceMap": true,
8
- "rootDir": ".",
9
- "strict": true
10
- },
11
- "exclude": [
12
- "node_modules",
13
- ".vscode-test"
14
- ]
15
- }