Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoTo Definition Support for LPython #3

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
902 changes: 902 additions & 0 deletions client/package-lock.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "lpyth-client",
"description": "VSCode part of LPython Language Server",
"author": "Ankita Sharma",
"license": "MIT",
"version": "0.0.1",
"publisher": "vscode",
"repository": {
"type": "git",
"url": "https://github.com/lcompilers/lpython-vscode-extension"
},
"engines": {
"vscode": "^1.63.0"
},
"dependencies": {
"vscode-languageclient": "^7.0.0"
},
"devDependencies": {
"@types/vscode": "^1.63.0",
"@vscode/test-electron": "^2.1.2"
}
}
65 changes: 65 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import * as path from 'path';
import { workspace, ExtensionContext } from 'vscode';

import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind
} from 'vscode-languageclient/node';

let client: LanguageClient;

export function activate(context: ExtensionContext) {
// The server is implemented in node
const serverModule = context.asAbsolutePath(
path.join('out', 'server', 'src', 'server.js')
);
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
const serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions
}
};

// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme: 'file', language: 'LPython' }],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
}
};

// Create the language client and start the client.
client = new LanguageClient(
'LPythonLanguageServer',
'LPython language server',
serverOptions,
clientOptions
);

// Start the client. This will also launch the server
client.start();
}

export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;
}
return client.stop();
}
12 changes: 12 additions & 0 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"lib": ["es2020"],
"outDir": "out",
"rootDir": "src",
"sourceMap": true
},
"include": ["src"],
"exclude": ["node_modules", ".vscode-test"]
}
56 changes: 56 additions & 0 deletions language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"comments": {
"lineComment": "#",
"blockComment": [ "\"\"\"", "\"\"\"" ]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "\"", "close": "\"", "notIn": ["string"] },
{ "open": "r\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "R\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "u\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "U\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "f\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "F\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "b\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "B\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "r'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "R'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "u'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "U'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "f'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "F'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "b'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "B'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "`", "close": "`", "notIn": ["string"] }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"],
["`", "`"]
],
"folding": {
"offSide": true,
"markers": {
"start": "^\\s*#\\s*region\\b",
"end": "^\\s*#\\s*endregion\\b"
}
},
"onEnterRules": [
{
"beforeText": "^\\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async).*?:\\s*$",
"action": { "indent": "indent" }
}
]
}
Loading