1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | require("apollo-env");
|
4 | require("apollo-env/lib/fetch/global");
|
5 | const node_1 = require("vscode-languageserver/node");
|
6 | const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
7 | const workspace_1 = require("./workspace");
|
8 | const languageProvider_1 = require("./languageProvider");
|
9 | const loadingHandler_1 = require("./loadingHandler");
|
10 | const utilities_1 = require("./utilities");
|
11 | const connection = (0, node_1.createConnection)(node_1.ProposedFeatures.all);
|
12 | utilities_1.Debug.SetConnection(connection);
|
13 | let hasWorkspaceFolderCapability = false;
|
14 | let initializeConnection;
|
15 | const whenConnectionInitialized = new Promise((resolve) => (initializeConnection = resolve));
|
16 | const workspace = new workspace_1.GraphQLWorkspace(new loadingHandler_1.LanguageServerLoadingHandler(connection), {
|
17 | clientIdentity: {
|
18 | name: process.env["APOLLO_CLIENT_NAME"],
|
19 | version: process.env["APOLLO_CLIENT_VERSION"],
|
20 | referenceID: process.env["APOLLO_CLIENT_REFERENCE_ID"],
|
21 | },
|
22 | });
|
23 | workspace.onDiagnostics((params) => {
|
24 | connection.sendDiagnostics(params);
|
25 | });
|
26 | workspace.onDecorations((params) => {
|
27 | connection.sendNotification("apollographql/engineDecorations", params);
|
28 | });
|
29 | workspace.onSchemaTags((params) => {
|
30 | connection.sendNotification("apollographql/tagsLoaded", JSON.stringify(params));
|
31 | });
|
32 | workspace.onConfigFilesFound(async (params) => {
|
33 | await whenConnectionInitialized;
|
34 | connection.sendNotification("apollographql/configFilesFound", params instanceof Error
|
35 | ?
|
36 | JSON.stringify({ message: params.message, stack: params.stack })
|
37 | : JSON.stringify(params));
|
38 | });
|
39 | connection.onInitialize(async ({ capabilities, workspaceFolders }) => {
|
40 | hasWorkspaceFolderCapability = !!(capabilities.workspace && capabilities.workspace.workspaceFolders);
|
41 | if (workspaceFolders) {
|
42 | await Promise.all(workspaceFolders.map((folder) => workspace.addProjectsInFolder(folder)));
|
43 | }
|
44 | return {
|
45 | capabilities: {
|
46 | hoverProvider: true,
|
47 | completionProvider: {
|
48 | resolveProvider: false,
|
49 | triggerCharacters: ["...", "@"],
|
50 | },
|
51 | definitionProvider: true,
|
52 | referencesProvider: true,
|
53 | documentSymbolProvider: true,
|
54 | workspaceSymbolProvider: true,
|
55 | codeLensProvider: {
|
56 | resolveProvider: false,
|
57 | },
|
58 | codeActionProvider: true,
|
59 | executeCommandProvider: {
|
60 | commands: [],
|
61 | },
|
62 | textDocumentSync: node_1.TextDocumentSyncKind.Incremental,
|
63 | },
|
64 | };
|
65 | });
|
66 | connection.onInitialized(async () => {
|
67 | initializeConnection();
|
68 | if (hasWorkspaceFolderCapability) {
|
69 | connection.workspace.onDidChangeWorkspaceFolders(async (event) => {
|
70 | await Promise.all([
|
71 | ...event.removed.map((folder) => workspace.removeProjectsInFolder(folder)),
|
72 | ...event.added.map((folder) => workspace.addProjectsInFolder(folder)),
|
73 | ]);
|
74 | });
|
75 | }
|
76 | });
|
77 | const documents = new node_1.TextDocuments(vscode_languageserver_textdocument_1.TextDocument);
|
78 | documents.listen(connection);
|
79 | documents.onDidChangeContent((0, utilities_1.debounceHandler)((params) => {
|
80 | const project = workspace.projectForFile(params.document.uri);
|
81 | if (!project)
|
82 | return;
|
83 | project.documentDidChange(params.document);
|
84 | }));
|
85 | connection.onDidChangeWatchedFiles((params) => {
|
86 | for (const { uri, type } of params.changes) {
|
87 | if (uri.endsWith("apollo.config.cjs") ||
|
88 | uri.endsWith("apollo.config.js") ||
|
89 | uri.endsWith(".env")) {
|
90 | workspace.reloadProjectForConfig(uri);
|
91 | }
|
92 | if (type === node_1.FileChangeType.Changed) {
|
93 | continue;
|
94 | }
|
95 | const project = workspace.projectForFile(uri);
|
96 | if (!project)
|
97 | continue;
|
98 | switch (type) {
|
99 | case node_1.FileChangeType.Created:
|
100 | project.fileDidChange(uri);
|
101 | break;
|
102 | case node_1.FileChangeType.Deleted:
|
103 | project.fileWasDeleted(uri);
|
104 | break;
|
105 | }
|
106 | }
|
107 | });
|
108 | const languageProvider = new languageProvider_1.GraphQLLanguageProvider(workspace);
|
109 | connection.onHover((params, token) => languageProvider.provideHover(params.textDocument.uri, params.position, token));
|
110 | connection.onDefinition((params, token) => languageProvider.provideDefinition(params.textDocument.uri, params.position, token));
|
111 | connection.onReferences((params, token) => languageProvider.provideReferences(params.textDocument.uri, params.position, params.context, token));
|
112 | connection.onDocumentSymbol((params, token) => languageProvider.provideDocumentSymbol(params.textDocument.uri, token));
|
113 | connection.onWorkspaceSymbol((params, token) => languageProvider.provideWorkspaceSymbol(params.query, token));
|
114 | connection.onCompletion((0, utilities_1.debounceHandler)((params, token) => languageProvider.provideCompletionItems(params.textDocument.uri, params.position, token)));
|
115 | connection.onCodeLens((0, utilities_1.debounceHandler)((params, token) => languageProvider.provideCodeLenses(params.textDocument.uri, token)));
|
116 | connection.onCodeAction((0, utilities_1.debounceHandler)((params, token) => languageProvider.provideCodeAction(params.textDocument.uri, params.range, token)));
|
117 | connection.onNotification("apollographql/reloadService", () => workspace.reloadService());
|
118 | connection.onNotification("apollographql/tagSelected", (selection) => workspace.updateSchemaTag(selection));
|
119 | connection.onNotification("apollographql/getStats", async ({ uri }) => {
|
120 | const status = await languageProvider.provideStats(uri);
|
121 | connection.sendNotification("apollographql/statsLoaded", status);
|
122 | });
|
123 | connection.listen();
|
124 |
|
\ | No newline at end of file |