diff options
-rw-r--r-- | client/src/extension.ts | 135 | ||||
-rw-r--r-- | server/src/diagnostics.ts | 2 | ||||
-rw-r--r-- | server/src/navigation.ts | 13 | ||||
-rw-r--r-- | server/src/parseDocument.ts | 6 | ||||
-rw-r--r-- | server/src/perl/lib_bs22/ModHunter.pl | 4 | ||||
-rw-r--r-- | server/src/perl/tidyWrapper.pl | 3 | ||||
-rw-r--r-- | server/src/types.ts | 2 |
7 files changed, 92 insertions, 73 deletions
diff --git a/client/src/extension.ts b/client/src/extension.ts index 363901e..8a41b8a 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -1,66 +1,69 @@ -/* --------------------------------------------------------------------------------------------
- * 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('server', 'out', '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 perl documents
- documentSelector: [{ scheme: 'file', language: 'perl' }],
- synchronize: {
- configurationSection: 'perlnavigator',
- // 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(
- 'perlnavigator',
- 'Perl Navigator LSP',
- 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();
-}
+/* -------------------------------------------------------------------------------------------- + * 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('server', 'out', '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 perl documents + documentSelector: [ + { scheme: 'file', language: 'perl' }, + { scheme: 'untitled', language: 'perl' } + ], + synchronize: { + configurationSection: 'perlnavigator', + // 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( + 'perlnavigator', + 'Perl Navigator LSP', + 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(); +} diff --git a/server/src/diagnostics.ts b/server/src/diagnostics.ts index f102b57..1892a91 100644 --- a/server/src/diagnostics.ts +++ b/server/src/diagnostics.ts @@ -56,7 +56,7 @@ export async function perlcompile(textDocument: TextDocument, workspaceFolders: } } - const perlDoc = await buildNav(stdout); + const perlDoc = await buildNav(stdout, filePath, textDocument.uri); output.split("\n").forEach(violation => { maybeAddCompDiag(violation, severity, diagnostics, filePath, perlDoc); diff --git a/server/src/navigation.ts b/server/src/navigation.ts index ae4f151..3778873 100644 --- a/server/src/navigation.ts +++ b/server/src/navigation.ts @@ -33,9 +33,16 @@ export function getDefinition(params: DefinitionParams, perlDoc: PerlDocument, t const elemResolved: PerlElem | undefined = resolveElemForNav(perlDoc, elem, symbol); if(!elemResolved) return; - // TODO: make this whole thing async - if(!existsSync(elemResolved.file)) return; // Make sure the file exists and hasn't been deleted. - let uri = Uri.file(realpathSync(elemResolved.file)).toString(); // Resolve symlinks + let uri: string; + if(perlDoc.filePath !== elemResolved.file){ // TODO Compare URI instead + // If sending to a different file, let's make sure it exists and clean up the path + if(!existsSync(elemResolved.file)) return; // Make sure the file exists and hasn't been deleted. + uri = Uri.file(realpathSync(elemResolved.file)).toString(); // Resolve symlinks + } else { + // Sending to current file (including untitled files) + uri = perlDoc.uri; + } + const newLoc: Location = { uri: uri, range: { diff --git a/server/src/parseDocument.ts b/server/src/parseDocument.ts index b678147..2de1302 100644 --- a/server/src/parseDocument.ts +++ b/server/src/parseDocument.ts @@ -2,7 +2,7 @@ import { PerlDocument, PerlElem, PerlImport, PerlSymbolKind} from "./types"; -export async function buildNav(stdout: string): Promise<PerlDocument> { +export async function buildNav(stdout: string, filePath: string, fileuri: string): Promise<PerlDocument> { stdout = stdout.replace(/\r/g, ""); // Windows @@ -10,7 +10,9 @@ export async function buildNav(stdout: string): Promise<PerlDocument> { elems: new Map(), canonicalElems: new Map(), imported: new Map(), - parents: new Map() + parents: new Map(), + filePath: filePath, + uri: fileuri, }; stdout.split("\n").forEach(perl_elem => { diff --git a/server/src/perl/lib_bs22/ModHunter.pl b/server/src/perl/lib_bs22/ModHunter.pl index a4564a3..c9e6344 100644 --- a/server/src/perl/lib_bs22/ModHunter.pl +++ b/server/src/perl/lib_bs22/ModHunter.pl @@ -84,6 +84,10 @@ sub myuniq { # my $start = Time::HiRes::time(); my $modsFound = get_modules(); +# Generally, having keywords like "if" provide hover or definitions as a module is more confusing than helpful. +my @modsToSkip = ('if', 'open', 'sort'); +delete $modsFound->{$_} foreach @modsToSkip; + print "Dumping Mods\n"; foreach my $mod (keys %$modsFound){ diff --git a/server/src/perl/tidyWrapper.pl b/server/src/perl/tidyWrapper.pl index 08843a1..b47a7e8 100644 --- a/server/src/perl/tidyWrapper.pl +++ b/server/src/perl/tidyWrapper.pl @@ -16,13 +16,14 @@ my $source = do { local $/; <STDIN> }; die("Did not pass any source via stdin") if !defined($source); die("PerlTidy profile not readable") if ($profile and !-f $profile); # Profie may be undef -my ($destination, $stderr, $argv); +my ($destination, $stderr, $formatErrors, $argv); my $error_flag = Perl::Tidy::perltidy( argv => $argv, source => \$source, destination => \$destination, stderr => \$stderr, + errorfile => \$formatErrors, # Important to make sure the user's workspace is not polluted with .ERR files perltidyrc => $profile, ); diff --git a/server/src/types.ts b/server/src/types.ts index d94e7dd..ab83c83 100644 --- a/server/src/types.ts +++ b/server/src/types.ts @@ -52,6 +52,8 @@ export interface PerlDocument { canonicalElems: Map<string, PerlElem>; imported: Map<string, number>; parents: Map<string, string>; + filePath: string; + uri: string; } export interface CompilationResults { |