@jpoly1219/context-extractor 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
package/dist/app.js CHANGED
@@ -32,8 +32,8 @@ const fs = __importStar(require("fs"));
32
32
  const child_process_1 = require("child_process");
33
33
  const child_process_2 = require("child_process");
34
34
  const openai_1 = __importDefault(require("openai"));
35
- // import { LspClient, JSONRPCEndpoint } from "../ts-lsp-client-dist/src/main";
36
- const ts_lsp_client_1 = require("ts-lsp-client");
35
+ const main_1 = require("../ts-lsp-client-dist/src/main");
36
+ // import { LspClient, JSONRPCEndpoint } from "ts-lsp-client";
37
37
  const types_1 = require("./types");
38
38
  // TODO: Bundle the drivers as barrel exports.
39
39
  const typescript_driver_1 = require("./typescript-driver");
@@ -89,8 +89,8 @@ class App {
89
89
  }
90
90
  }
91
91
  })();
92
- const e = new ts_lsp_client_1.JSONRPCEndpoint(r.stdin, r.stdout);
93
- const c = new ts_lsp_client_1.LspClient(e);
92
+ const e = new main_1.JSONRPCEndpoint(r.stdin, r.stdout);
93
+ const c = new main_1.LspClient(e);
94
94
  this.languageServer = r;
95
95
  this.lspClient = c;
96
96
  this.languageServer.on('close', (code) => {
package/dist/core.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { LspClient } from "ts-lsp-client";
2
+ import { LspClient } from "../ts-lsp-client-dist/src/main.js";
3
3
  import * as fs from "fs";
4
4
  declare const getAnnotatedFunctionHoleContext: (sketchFileContent: string) => {
5
5
  functionName: string;
package/dist/core.js CHANGED
@@ -24,6 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.normalize = exports.extractRelevantHeaders = exports.extractRelevantTypes = exports.getHoleContext = exports.getAnnotatedFunctionHoleContext = void 0;
27
+ // import { LspClient, MarkupContent, Location, SymbolInformation, Range } from "ts-lsp-client"
28
+ // import { LspClient, MarkupContent, Location, SymbolInformation, Range } from "dist/ts-lsp-client-dist/src/main"
27
29
  const utils_js_1 = require("./utils.js");
28
30
  const fs = __importStar(require("fs"));
29
31
  const child_process_1 = require("child_process");
package/dist/main.js CHANGED
@@ -24,8 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.completeWithLLM = exports.extractContext = exports.extractWithCodeQL = exports.extract = void 0;
27
- // import { JSONRPCEndpoint, LspClient, ClientCapabilities } from "../ts-lsp-client-dist/src/main.js"
28
- const ts_lsp_client_1 = require("ts-lsp-client");
27
+ const main_js_1 = require("../ts-lsp-client-dist/src/main.js");
28
+ // import { JSONRPCEndpoint, LspClient, ClientCapabilities } from "ts-lsp-client"
29
+ // import { JSONRPCEndpoint, LspClient, ClientCapabilities } from "dist/ts-lsp-client-dist/src/main"
29
30
  const child_process_1 = require("child_process");
30
31
  const fs = __importStar(require("fs"));
31
32
  const path = __importStar(require("path"));
@@ -42,8 +43,8 @@ const extract = async (sketchPath) => {
42
43
  const workspaceFolders = [{ 'name': 'context-extractor', 'uri': rootUri }];
43
44
  // initialize LS client and server
44
45
  const r = (0, child_process_1.spawn)('typescript-language-server', ['--stdio']);
45
- const e = new ts_lsp_client_1.JSONRPCEndpoint(r.stdin, r.stdout);
46
- const c = new ts_lsp_client_1.LspClient(e);
46
+ const e = new main_js_1.JSONRPCEndpoint(r.stdin, r.stdout);
47
+ const c = new main_js_1.LspClient(e);
47
48
  console.log(JSON.stringify(c));
48
49
  const capabilities = {
49
50
  'textDocument': {
@@ -1,4 +1,4 @@
1
- import { LspClient, Range } from "ts-lsp-client";
1
+ import { LspClient, Range } from "../ts-lsp-client-dist/src/main";
2
2
  import { LanguageDriver, TypeSpanAndSourceFile } from "./types";
3
3
  import { OcamlTypeChecker } from "./ocaml-type-checker";
4
4
  export declare class OcamlDriver implements LanguageDriver {
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { JSONRPCClient } from 'json-rpc-2.0';
4
+ import { EventEmitter, Readable, TransformOptions, Writable } from 'stream';
5
+ import { JSONRPCParams } from "json-rpc-2.0/dist/models";
6
+ export declare class JSONRPCEndpoint extends EventEmitter {
7
+ private writable;
8
+ private readable;
9
+ private readableByline;
10
+ private client;
11
+ private nextId;
12
+ constructor(writable: Writable, readable: Readable, options?: ConstructorParameters<typeof EventEmitter>[0] & TransformOptions);
13
+ send(method: string, message?: JSONRPCParams): ReturnType<JSONRPCClient["request"]>;
14
+ notify(method: string, message?: JSONRPCParams): void;
15
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JSONRPCEndpoint = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const json_rpc_2_0_1 = require("json-rpc-2.0");
6
+ const stream_1 = require("stream");
7
+ const jsonRpcTransform_1 = require("./jsonRpcTransform");
8
+ const logger_1 = require("./logger");
9
+ class JSONRPCEndpoint extends stream_1.EventEmitter {
10
+ constructor(writable, readable, options) {
11
+ super(options);
12
+ this.nextId = 0;
13
+ const createId = () => this.nextId++;
14
+ this.writable = writable;
15
+ this.readable = readable;
16
+ this.readableByline = jsonRpcTransform_1.JSONRPCTransform.createStream(this.readable, options);
17
+ this.client = new json_rpc_2_0_1.JSONRPCClient((jsonRPCRequest) => tslib_1.__awaiter(this, void 0, void 0, function* () {
18
+ const jsonRPCRequestStr = JSON.stringify(jsonRPCRequest);
19
+ logger_1.Logger.log(`sending: ${jsonRPCRequestStr}`, logger_1.LoggerLevel.DEBUG);
20
+ this.writable.write(`Content-Length: ${jsonRPCRequestStr.length}\r\n\r\n${jsonRPCRequestStr}`);
21
+ }), createId);
22
+ this.readableByline.on('data', (jsonRPCResponseOrRequest) => {
23
+ const jsonrpc = JSON.parse(jsonRPCResponseOrRequest);
24
+ logger_1.Logger.log(`[transform] ${jsonRPCResponseOrRequest}`, logger_1.LoggerLevel.DEBUG);
25
+ if (Object.prototype.hasOwnProperty.call(jsonrpc, 'id')) {
26
+ const jsonRPCResponse = jsonrpc;
27
+ if (jsonRPCResponse.id === (this.nextId - 1)) {
28
+ this.client.receive(jsonRPCResponse);
29
+ }
30
+ else {
31
+ logger_1.Logger.log(`[transform] ${jsonRPCResponseOrRequest}`, logger_1.LoggerLevel.ERROR);
32
+ }
33
+ }
34
+ else {
35
+ const jsonRPCRequest = jsonrpc;
36
+ this.emit(jsonRPCRequest.method, jsonRPCRequest.params);
37
+ }
38
+ });
39
+ }
40
+ send(method, message) {
41
+ return this.client.request(method, message);
42
+ }
43
+ notify(method, message) {
44
+ this.client.notify(method, message);
45
+ }
46
+ }
47
+ exports.JSONRPCEndpoint = JSONRPCEndpoint;
48
+ //# sourceMappingURL=jsonRpcEndpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonRpcEndpoint.js","sourceRoot":"","sources":["../../src/jsonRpcEndpoint.ts"],"names":[],"mappings":";;;;AAAA,+CAA8E;AAC9E,mCAA4E;AAC5E,yDAAsD;AACtD,qCAA+C;AAG/C,MAAa,eAAgB,SAAQ,qBAAY;IAQ/C,YAAmB,QAAkB,EAAE,QAAkB,EAAE,OAA0E;QACnI,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,mCAAgB,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAE5E,IAAI,CAAC,MAAM,GAAG,IAAI,4BAAa,CAAC,CAAO,cAAc,EAAE,EAAE;YACvD,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;YACzD,eAAM,CAAC,GAAG,CAAC,YAAY,iBAAi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AC;IACtC,CAAC;CACF;AAnDD,0CAmDC"}
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Readable, Transform, TransformCallback, TransformOptions } from "stream";
4
+ export declare class JSONRPCTransform extends Transform {
5
+ private _state;
6
+ private _curContentLength;
7
+ private _curChunk;
8
+ private constructor();
9
+ _transform(chunk: Buffer | string, encoding: BufferEncoding, done: TransformCallback): void;
10
+ private _reencode;
11
+ static createStream(readStream?: Readable, options?: TransformOptions): JSONRPCTransform;
12
+ }
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JSONRPCTransform = void 0;
4
+ const stream_1 = require("stream");
5
+ class JSONRPCTransform extends stream_1.Transform {
6
+ constructor(options) {
7
+ options = options || {};
8
+ options.objectMode = true;
9
+ super(options);
10
+ this.on('pipe', (src) => {
11
+ if (!this.readableEncoding) {
12
+ if (src instanceof stream_1.Readable) {
13
+ this.setEncoding(src.readableEncoding);
14
+ }
15
+ }
16
+ });
17
+ this._curChunk = Buffer.from([]);
18
+ this._state = 'header';
19
+ }
20
+ _transform(chunk, encoding, done) {
21
+ encoding = encoding || 'utf8';
22
+ if (!Buffer.isBuffer(chunk)) {
23
+ chunk = Buffer.from(chunk, encoding);
24
+ }
25
+ this._curChunk = Buffer.concat([this._curChunk, chunk]);
26
+ const prefixMinLength = Buffer.byteLength('Content-Length: 0\r\n\r\n', encoding);
27
+ const prefixLength = Buffer.byteLength('Content-Length: ', encoding);
28
+ const prefixRegex = /^Content-Length: /i;
29
+ const contentTypeLength = Buffer.byteLength('Content-Type: ', encoding);
30
+ const contentTypeRe = /^Content-Type: /i;
31
+ const digitLength = Buffer.byteLength('0', encoding);
32
+ const digitRe = /^[0-9]/;
33
+ const suffixLength = Buffer.byteLength('\r\n\r\n', encoding);
34
+ const suffixRe = /\r\n\r\n/;
35
+ const crlfLength = Buffer.byteLength('\r\n', encoding);
36
+ const crlfRe = /^\r\n/;
37
+ while (true) {
38
+ if (this._state === 'header') {
39
+ if (this._curChunk.length < prefixMinLength)
40
+ break;
41
+ const leading = this._curChunk.slice(0, prefixLength);
42
+ if (!prefixRegex.test(leading.toString(encoding))) {
43
+ done(new Error(`[_transform] Bad header: ${this._curChunk.toString(encoding)}`));
44
+ return;
45
+ }
46
+ let numString = '';
47
+ let position = leading.length;
48
+ while (this._curChunk.length - position > digitLength) {
49
+ const ch = this._curChunk.slice(position, position + digitLength).toString(encoding);
50
+ if (!digitRe.test(ch))
51
+ break;
52
+ numString += ch;
53
+ position += 1;
54
+ }
55
+ if (position === leading.length || this._curChunk.length - position < crlfLength) {
56
+ done(new Error(`[_transform] Bad header: ${this._curChunk.toString(encoding)}`));
57
+ return;
58
+ }
59
+ this._curContentLength = Number(numString);
60
+ this._curChunk = this._curChunk.slice(position + crlfLength);
61
+ const ctyp = this._curChunk.slice(0, contentTypeLength);
62
+ const noCtyp = this._curChunk.slice(0, crlfLength);
63
+ const isCtyp = contentTypeRe.test(ctyp.toString(encoding));
64
+ const isNoCtyp = crlfRe.test(noCtyp.toString(encoding));
65
+ if (!isNoCtyp && !isCtyp) {
66
+ done(new Error(`[_transform] Bad header: ${this._curChunk.toString(encoding)}`));
67
+ return;
68
+ }
69
+ if (isNoCtyp) {
70
+ this._curChunk = this._curChunk.slice(crlfLength);
71
+ }
72
+ if (isCtyp) {
73
+ const index = this._curChunk.toString(encoding).search(suffixRe);
74
+ if (index === -1) {
75
+ done(new Error(`[_transform] Bad header: ${this._curChunk.toString(encoding)}`));
76
+ return;
77
+ }
78
+ position = index;
79
+ this._curChunk = this._curChunk.slice(position + suffixLength);
80
+ }
81
+ this._state = 'jsonrpc';
82
+ }
83
+ if (this._state === 'jsonrpc') {
84
+ if (this._curChunk.length >= this._curContentLength) {
85
+ this.push(this._reencode(this._curChunk.slice(0, this._curContentLength), encoding));
86
+ this._curChunk = this._curChunk.slice(this._curContentLength);
87
+ this._state = 'header';
88
+ continue;
89
+ }
90
+ }
91
+ break;
92
+ }
93
+ done();
94
+ }
95
+ _reencode(chunk, chunkEncoding) {
96
+ if (this.readableEncoding && this.readableEncoding != chunkEncoding) {
97
+ return chunk.toString(this.readableEncoding);
98
+ }
99
+ else if (this.readableEncoding) {
100
+ return chunk.toString(chunkEncoding);
101
+ }
102
+ else {
103
+ return chunk;
104
+ }
105
+ }
106
+ ;
107
+ static createStream(readStream, options) {
108
+ const jrt = new JSONRPCTransform(options);
109
+ if (readStream) {
110
+ readStream.pipe(jrt);
111
+ }
112
+ return jrt;
113
+ }
114
+ }
115
+ exports.JSONRPCTransform = JSONRPCTransform;
116
+ //# sourceMappingURL=jsonRpcTransform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonRpcTransform.js","sourceRoot":"","sources":["../../src/jsonRpcTransform.ts"],"names":[],"mappings":";;;AAAA,mCAAkF;AAIlF,MAAa,gBAAiB,SAAQ,kBAAS;IAK7C,YAAoB,OAA0B;QAC5C,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QACxB,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;YACtB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;gBAC1B,IAAI,GAAG,YAAY,iBAAQ,EAAE;oBAC3B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;iBACxC;aACF;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;IACzB,CAAC;IAGM,UAAU,CAAC,KAAsB,EAAE,QAAwB,EAAE,IAAuB;QAEzF,QAAQ,GAAG,QAAQ,IAAI,MAAM,CAAC;QAE9B,IAAI,CAAC,MAAM,CAAC,QAAQ,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rF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;oBAC9D,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;oBAEvB,SAAS;iBACV;aACF;YAED,MAAM;SACP;QACD,IAAI,EAAE,CAAC;IACT,CAAC;IAEO,SAAS,CAAC,KAAa,EAAE,aAA6B;QAC5D,IAAI,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,gBAAgB,IAAI,aAAa,EAAE;YACnE,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;SAC9C;aAAM,IAAI,IAAI,CAAC,gBAAgB,EAAE;YAEhC,OAAO,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;SACtC;aAAM;YACL,OAAO,KAAK,CAAC;SACd;IACH,CAAC;IAAA,CAAC;IAEK,MAAM,CAAC,YAAY,CAAC,UAAqB,EAAE,OAA0B;QAC1E,MAAM,GAAG,GAAG,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,UAAU,EAAE;YACd,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SACtB;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AA5ID,4CA4IC"}
@@ -0,0 +1,14 @@
1
+ export declare enum LoggerLevel {
2
+ TRACE = "10",
3
+ DEBUG = "20",
4
+ INFO = "30",
5
+ WARN = "40",
6
+ ERROR = "50",
7
+ FATAL = "60"
8
+ }
9
+ export declare class Logger {
10
+ static setLogLevel(logLevel: string, isJsonFormatEnabled: boolean): void;
11
+ static log(message: string, logLevel: LoggerLevel): void;
12
+ private static logger;
13
+ private static isJsonFormatEnabled;
14
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = exports.LoggerLevel = void 0;
4
+ const pino_1 = require("pino");
5
+ var LoggerLevel;
6
+ (function (LoggerLevel) {
7
+ LoggerLevel["TRACE"] = "10";
8
+ LoggerLevel["DEBUG"] = "20";
9
+ LoggerLevel["INFO"] = "30";
10
+ LoggerLevel["WARN"] = "40";
11
+ LoggerLevel["ERROR"] = "50";
12
+ LoggerLevel["FATAL"] = "60";
13
+ })(LoggerLevel = exports.LoggerLevel || (exports.LoggerLevel = {}));
14
+ class Logger {
15
+ static setLogLevel(logLevel, isJsonFormatEnabled) {
16
+ logLevel = logLevel.toLowerCase();
17
+ this.isJsonFormatEnabled = isJsonFormatEnabled;
18
+ if (!isJsonFormatEnabled) {
19
+ this.logger = (0, pino_1.default)({
20
+ name: 'ts-lsp-client',
21
+ level: logLevel,
22
+ prettyPrint: {
23
+ levelFirst: true,
24
+ colorize: true,
25
+ translateTime: true,
26
+ ignore: 'pid,hostname'
27
+ }
28
+ });
29
+ }
30
+ else {
31
+ }
32
+ }
33
+ static log(message, logLevel) {
34
+ if (this.logger === null || this.logger === undefined)
35
+ return;
36
+ if (this.isJsonFormatEnabled)
37
+ return;
38
+ switch (logLevel) {
39
+ case LoggerLevel.TRACE:
40
+ this.logger.trace(message);
41
+ break;
42
+ case LoggerLevel.DEBUG:
43
+ this.logger.debug(message);
44
+ break;
45
+ case LoggerLevel.INFO:
46
+ this.logger.info(message);
47
+ break;
48
+ case LoggerLevel.WARN:
49
+ this.logger.warn(message);
50
+ break;
51
+ case LoggerLevel.ERROR:
52
+ this.logger.error(message);
53
+ break;
54
+ case LoggerLevel.FATAL:
55
+ this.logger.fatal(message);
56
+ break;
57
+ }
58
+ }
59
+ }
60
+ exports.Logger = Logger;
61
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":";;;AAAA,+BAAwB;AAExB,IAAY,WAOX;AAPD,WAAY,WAAW;IACrB,2BAAY,CAAA;IACZ,2BAAY,CAAA;IACZ,0BAAW,CAAA;IACX,0BAAW,CAAA;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AAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAC3B,MAAM;YACR,KAAK,WAAW,CAAC,KAAK;gBACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAC3B,MAAM;SACT;IACH,CAAC;CAKF;AAjDD,wBAiDC"}
@@ -0,0 +1,32 @@
1
+ /// <reference types="node" />
2
+ import { JSONRPCEndpoint } from "./jsonRpcEndpoint";
3
+ import { DefinitionParams, DidChangeTextDocumentParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams, DocumentSymbol, DocumentSymbolParams, InitializeParams, InitializeResult, LocationLink, ReferenceParams, ResponseError, ShutdownResult, SignatureHelp, SignatureHelpParams, SymbolInformation, TypeDefinitionParams, Location, HoverParams, Hover, DeclarationParams, CompletionParams, CompletionItem, CompletionList, InlayHintParams, InlayHint, TypeHierarchyPrepareParams, TypeHierarchyItem, Range, DocumentDiagnosticParams, DocumentDiagnosticReport, OcamlTypedHolesParams, OcamlHoverExtendedParams, OcamlInferIntfParams, OcamlMerlinCallCompatibleParams, OcamlMerlinCallCompatibleResponse, OcamlTypeEnclosingParams, OcamlTypeEnclosingResponse, OcamlInferIntfResponse } from "./models";
4
+ import { once } from 'events';
5
+ export declare class LspClient {
6
+ private endpoint;
7
+ constructor(endpoint: JSONRPCEndpoint);
8
+ initialize(params: InitializeParams): PromiseLike<InitializeResult>;
9
+ initialized(): void;
10
+ shutdown(): PromiseLike<ShutdownResult>;
11
+ exit(): void;
12
+ didOpen(params: DidOpenTextDocumentParams): void;
13
+ didClose(params: DidCloseTextDocumentParams): void;
14
+ didChange(params: DidChangeTextDocumentParams): void;
15
+ documentSymbol(params: DocumentSymbolParams): PromiseLike<DocumentSymbol[] | SymbolInformation[] | null>;
16
+ references(params: ReferenceParams): PromiseLike<Location[] | ResponseError | null>;
17
+ definition(params: DefinitionParams): PromiseLike<Location | Location[] | LocationLink[] | ResponseError | null>;
18
+ typeDefinition(params: TypeDefinitionParams): PromiseLike<Location | Location[] | LocationLink[] | ResponseError | null>;
19
+ signatureHelp(params: SignatureHelpParams): PromiseLike<SignatureHelp | null>;
20
+ once(method: string): ReturnType<typeof once>;
21
+ hover(params: HoverParams): PromiseLike<Hover>;
22
+ gotoDeclaration(params: DeclarationParams): PromiseLike<Location | Location[] | LocationLink[] | null>;
23
+ completion(params: CompletionParams): PromiseLike<CompletionItem[] | CompletionList | null>;
24
+ inlayHint(params: InlayHintParams): PromiseLike<InlayHint[] | null>;
25
+ prepareTypeHierarchy(params: TypeHierarchyPrepareParams): PromiseLike<TypeHierarchyItem[] | null>;
26
+ diagnostics(params: DocumentDiagnosticParams): PromiseLike<DocumentDiagnosticReport | null>;
27
+ ocamlTypedHoles(params: OcamlTypedHolesParams): PromiseLike<Range[] | null>;
28
+ ocamlHoverExtended(params: OcamlHoverExtendedParams): PromiseLike<Hover>;
29
+ ocamlInferIntf(params: OcamlInferIntfParams): PromiseLike<OcamlInferIntfResponse | null>;
30
+ ocamlMerlinCallCompatible(params: OcamlMerlinCallCompatibleParams): PromiseLike<OcamlMerlinCallCompatibleResponse>;
31
+ ocamlTypeEnclosing(params: OcamlTypeEnclosingParams): PromiseLike<OcamlTypeEnclosingResponse>;
32
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LspClient = void 0;
4
+ const events_1 = require("events");
5
+ class LspClient {
6
+ constructor(endpoint) {
7
+ this.endpoint = endpoint;
8
+ }
9
+ initialize(params) {
10
+ return this.endpoint.send('initialize', params);
11
+ }
12
+ initialized() {
13
+ this.endpoint.notify('initialized');
14
+ }
15
+ shutdown() {
16
+ return this.endpoint.send('shutdown');
17
+ }
18
+ exit() {
19
+ this.endpoint.notify('exit');
20
+ }
21
+ didOpen(params) {
22
+ this.endpoint.notify('textDocument/didOpen', params);
23
+ }
24
+ didClose(params) {
25
+ this.endpoint.notify('textDocument/didClose', params);
26
+ }
27
+ didChange(params) {
28
+ this.endpoint.notify('textDocument/didChange', params);
29
+ }
30
+ documentSymbol(params) {
31
+ return this.endpoint.send('textDocument/documentSymbol', params);
32
+ }
33
+ references(params) {
34
+ return this.endpoint.send('textDocument/references', params);
35
+ }
36
+ definition(params) {
37
+ return this.endpoint.send('textDocument/definition', params);
38
+ }
39
+ typeDefinition(params) {
40
+ return this.endpoint.send('textDocument/typeDefinition', params);
41
+ }
42
+ signatureHelp(params) {
43
+ return this.endpoint.send('textDocument/signatureHelp', params);
44
+ }
45
+ once(method) {
46
+ return (0, events_1.once)(this.endpoint, method);
47
+ }
48
+ hover(params) {
49
+ return this.endpoint.send('textDocument/hover', params);
50
+ }
51
+ gotoDeclaration(params) {
52
+ return this.endpoint.send('textDocument/declaration', params);
53
+ }
54
+ completion(params) {
55
+ return this.endpoint.send('textDocument/completion', params);
56
+ }
57
+ inlayHint(params) {
58
+ return this.endpoint.send('textDocument/inlayHint', params);
59
+ }
60
+ prepareTypeHierarchy(params) {
61
+ return this.endpoint.send('textDocument/prepareTypeHierarchy', params);
62
+ }
63
+ diagnostics(params) {
64
+ return this.endpoint.send('textDocument/diagnostic', params);
65
+ }
66
+ ocamlTypedHoles(params) {
67
+ return this.endpoint.send('ocamllsp/typedHoles', params);
68
+ }
69
+ ocamlHoverExtended(params) {
70
+ return this.endpoint.send('ocamllsp/hoverExtended', params);
71
+ }
72
+ ocamlInferIntf(params) {
73
+ return this.endpoint.send('ocamllsp/inferIntf', params);
74
+ }
75
+ ocamlMerlinCallCompatible(params) {
76
+ return this.endpoint.send('ocamllsp/merlinCallCompatible', params);
77
+ }
78
+ ocamlTypeEnclosing(params) {
79
+ return this.endpoint.send('ocamllsp/typeEnclosing', params);
80
+ }
81
+ }
82
+ exports.LspClient = LspClient;
83
+ //# sourceMappingURL=lspClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lspClient.js","sourceRoot":"","sources":["../../src/lspClient.ts"],"names":[],"mappings":";;;AAyCA,mCAA8B;AAC9B,MA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AAC,CAAC;IAC9D,CAAC;IAEM,cAAc,CAAC,MAA4B;QAChD,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAEM,yBAAyB,CAAC,MAAuC;QACtE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,+BAA+B,EAAE,MAAM,CAAC,CAAC;IACrE,CAAC;IAEM,kBAAkB,CAAC,MAAgC;QACxD,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;CACF;AAxGD,8BAwGC"}
@@ -0,0 +1,4 @@
1
+ export * from './lspClient';
2
+ export * from './jsonRpcTransform';
3
+ export * from './jsonRpcEndpoint';
4
+ export * from './models';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lspClient"), exports);
5
+ tslib_1.__exportStar(require("./jsonRpcTransform"), exports);
6
+ tslib_1.__exportStar(require("./jsonRpcEndpoint"), exports);
7
+ tslib_1.__exportStar(require("./models"), exports);
8
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,6DAAmC;AACnC,4DAAkC;AAClC,mDAAyB"}