Example #1
0
export function activate(context: ExtensionContext) {
  const gist = new GistService(context.globalState);
  const cmd = new Commands({ gist });

  const subscriptions = context.subscriptions;
  const registerCommand = commands.registerCommand;

  // This will need to be removed in a future release
  const deprecatedToken = workspace.getConfiguration('gist').get<string>('oauth_token');
  if (deprecatedToken) {
    gist.setToken(deprecatedToken);
  }

  subscriptions.push(
    registerCommand('extension.openCodeBlock', cmd.openCodeBlock, cmd),
    registerCommand('extension.openFavoriteCodeBlock', cmd.openCodeBlock.bind(cmd, true)),
    registerCommand('extension.createCodeBlock', cmd.createCodeBlock, cmd),
    registerCommand('extension.openCodeBlockInBrowser', cmd.openCodeBlockInBrowser, cmd),
    registerCommand('extension.deleteCodeBlock', cmd.deleteCodeBlock, cmd),
    registerCommand('extension.removeFileFromCodeBlock', cmd.removeFileFromCodeBlock, cmd),
    registerCommand('extension.addToCodeBlock', cmd.addToCodeBlock, cmd),
    registerCommand('extension.changeCodeBlockDescription', cmd.changeCodeBlockDescription, cmd)
  );
  workspace.onDidSaveTextDocument(cmd.onSaveTextDocument, cmd);
}
Example #2
0
export function setup(disposables, flowPath) {

  lastDiagnostics = vscode.languages.createDiagnosticCollection();

  // Do an initial call to get diagnostics from the active editor if any
  if (vscode.window.activeTextEditor) {
    console.log('INIT');
    fullDiagnostics(flowPath);
  }

  // Update diagnostics: when active text editor changes
  disposables.push(vscode.window.onDidChangeActiveTextEditor(editor => {
    console.log('CHANGE');
    fileDiagnostics(editor && editor.document, flowPath);
  }));

  // Update diagnostics when document is edited
  disposables.push(vscode.workspace.onDidChangeTextDocument(event => {
    console.log('EDIT');
    if (vscode.window.activeTextEditor) {
      fileDiagnostics(vscode.window.activeTextEditor.document, flowPath);
    }
  }));

  // Update diagnostics when document is saved
  disposables.push(vscode.workspace.onDidSaveTextDocument(event => {
    console.log('SAVE');
    if (vscode.window.activeTextEditor) {
      fullDiagnostics(flowPath);
    }
  }));

}
Example #3
0
function loadConfiguration(context: ExtensionContext): void {
	const section = workspace.getConfiguration('npm');
	if (section) {
		validationEnabled = section.get<boolean>('validate.enable', true);
	}
	diagnosticCollection.clear();

	if (validationEnabled) {
		workspace.onDidSaveTextDocument(document => {
			validateDocument(document);
		}, null, context.subscriptions);
		window.onDidChangeActiveTextEditor(editor => {
			if (editor && editor.document) {
				validateDocument(editor.document);
			}
		}, null, context.subscriptions);

		// remove markers on close
		workspace.onDidCloseTextDocument(_document => {
			diagnosticCollection.clear();
		}, null, context.subscriptions);

		// workaround for onDidOpenTextDocument
		// workspace.onDidOpenTextDocument(document => {
		// 	console.log("onDidOpenTextDocument ", document.fileName);
		// 	validateDocument(document);
		// }, null, context.subscriptions);
		validateAllDocuments();
	}
}
Example #4
0
const startLinting = (context: ExtensionContext): void => {
    const diagnostics = vscode.languages.createDiagnosticCollection("fish");
    context.subscriptions.push(diagnostics);

    const lint = (document: TextDocument) => {
        if (isSavedFishDocument(document)) {
            return getDiagnostics(document)
                .catch((error) => {
                    vscode.window.showErrorMessage(error.toString());
                    diagnostics.delete(document.uri);
                })
                // tslint:disable-next-line:readonly-array
                .then((d) => diagnostics.set(document.uri, d as Diagnostic[]));
        } else {
            Promise.resolve();
        }
    };

    vscode.workspace.onDidOpenTextDocument(lint, null, context.subscriptions);
    vscode.workspace.onDidSaveTextDocument(lint, null, context.subscriptions);
    vscode.workspace.textDocuments.forEach(lint);

    // Remove diagnostics for closed files
    vscode.workspace.onDidCloseTextDocument(
        (d) => diagnostics.delete(d.uri), null, context.subscriptions);
};
export function activate(context: vscode.ExtensionContext): void {
    'use strict';

    const diag = vscode.languages.createDiagnosticCollection('ruby');
    context.subscriptions.push(diag);
    const rubocop = new Rubocop(diag);
    const rubocopAutocorrect = new RubocopAutocorrect(diag);

    const disposable = vscode.commands.registerCommand('ruby.rubocop', () => {
        const document = vscode.window.activeTextEditor.document;
        rubocop.execute(document);
    });

    vscode.commands.registerCommand('ruby.rubocopAutocorrect', () => {
        const document = vscode.window.activeTextEditor.document;
        rubocopAutocorrect.execute(document);
    });

    context.subscriptions.push(disposable);

    vscode.workspace.onDidSaveTextDocument((e: vscode.TextDocument) => {
        if (rubocop.isOnSave) {
            rubocop.execute(e);
        }
    });
}
Example #6
0
export async function activate(context: ExtensionContext) {
    const logger = new Logger();

    let requestController = new RequestController(context, logger);
    let historyController = new HistoryController(logger);
    let responseController = new ResponseController();
    let codeSnippetController = new CodeSnippetController();
    let environmentController = new EnvironmentController(await EnvironmentController.getCurrentEnvironment());
    context.subscriptions.push(requestController);
    context.subscriptions.push(historyController);
    context.subscriptions.push(responseController);
    context.subscriptions.push(codeSnippetController);
    context.subscriptions.push(environmentController);
    context.subscriptions.push(commands.registerCommand('rest-client.request', ((document: TextDocument, range: Range) => requestController.run(range))));
    context.subscriptions.push(commands.registerCommand('rest-client.rerun-last-request', () => requestController.rerun()));
    context.subscriptions.push(commands.registerCommand('rest-client.cancel-request', () => requestController.cancel()));
    context.subscriptions.push(commands.registerCommand('rest-client.history', () => historyController.save()));
    context.subscriptions.push(commands.registerCommand('rest-client.clear-history', () => historyController.clear()));
    context.subscriptions.push(commands.registerCommand('rest-client.save-response', () => responseController.save()));
    context.subscriptions.push(commands.registerCommand('rest-client.save-response-body', () => responseController.saveBody()));
    context.subscriptions.push(commands.registerCommand('rest-client.copy-response-body', () => responseController.copyBody()));
    context.subscriptions.push(commands.registerCommand('rest-client.generate-codesnippet', () => codeSnippetController.run()));
    context.subscriptions.push(commands.registerCommand('rest-client.copy-codesnippet', () => codeSnippetController.copy()));
    context.subscriptions.push(commands.registerCommand('rest-client.copy-request-as-curl', () => codeSnippetController.copyAsCurl()));
    context.subscriptions.push(commands.registerCommand('rest-client.switch-environment', () => environmentController.switchEnvironment()));
    context.subscriptions.push(commands.registerCommand('rest-client.clear-aad-token-cache', () => AadTokenCache.clear()));
    context.subscriptions.push(commands.registerCommand('rest-client._openDocumentLink', args => {
        workspace.openTextDocument(Uri.parse(args.path)).then(window.showTextDocument, error => {
            window.showErrorMessage(error.message);
        });
    }));

    const documentSelector = [
        { language: 'http', scheme: 'file' },
        { language: 'http', scheme: 'untitled' },
    ];

    context.subscriptions.push(languages.registerCompletionItemProvider(documentSelector, new HttpCompletionItemProvider()));
    context.subscriptions.push(languages.registerCompletionItemProvider(documentSelector, new RequestVariableCompletionItemProvider(), '.'));
    context.subscriptions.push(languages.registerHoverProvider(documentSelector, new CustomVariableHoverProvider()));
    context.subscriptions.push(languages.registerHoverProvider(documentSelector, new RequestVariableHoverProvider()));
    context.subscriptions.push(
        new ConfigurationDependentRegistration(
            () => languages.registerCodeLensProvider(documentSelector, new HttpCodeLensProvider()),
            s => s.enableSendRequestCodeLens));
    context.subscriptions.push(
        new ConfigurationDependentRegistration(
            () => languages.registerCodeLensProvider(documentSelector, new CustomVariableReferencesCodeLensProvider()),
            s => s.enableCustomVariableReferencesCodeLens));
    context.subscriptions.push(languages.registerDocumentLinkProvider(documentSelector, new RequestBodyDocumentLinkProvider()));
    context.subscriptions.push(languages.registerDefinitionProvider(documentSelector, new CustomVariableDefinitionProvider()));
    context.subscriptions.push(languages.registerReferenceProvider(documentSelector, new CustomVariableReferenceProvider()));
    context.subscriptions.push(languages.registerDocumentSymbolProvider(documentSelector, new HttpDocumentSymbolProvider()));

    const diagnosticsProviders = new VariableDiagnosticsProvider();
    workspace.onDidOpenTextDocument(diagnosticsProviders.checkVariables, diagnosticsProviders, context.subscriptions);
    workspace.onDidCloseTextDocument(diagnosticsProviders.deleteDocumentFromDiagnosticCollection, diagnosticsProviders, context.subscriptions);
    workspace.onDidSaveTextDocument(diagnosticsProviders.checkVariables, diagnosticsProviders, context.subscriptions);
}
Example #7
0
function startLintOnSaveWatcher(mlintPath: string) {

	function mapSeverityToVSCodeSeverity(sev: string) {
		switch (sev) {
			case "error": return vscode.DiagnosticSeverity.Error;
			case "warning": return vscode.DiagnosticSeverity.Warning;
			default: return vscode.DiagnosticSeverity.Error;
		}
	}

	let matlabConfig = vscode.workspace.getConfiguration('matlab');

	return workspace.onDidSaveTextDocument(document => {
		if (document.languageId != "matlab") {
			return;
		}

		check(document.uri.fsPath, matlabConfig['lintOnSave'], mlintPath).then(errors => {
			diagnosticCollection.clear();

			let diagnosticMap: Map<vscode.Uri, vscode.Diagnostic[]> = new Map();;

			errors.forEach(error => {
				let targetUri = vscode.Uri.file(error.file);

				var line = error.line - 1;
				if (line < 0) line = 0;

				var startColumn = error.column[0] - 1;
				if (startColumn < 0) startColumn = 0;

				var endColumn = error.column[1] - 1;
				if (endColumn < 0) endColumn = 0;

				let range = new vscode.Range(line, startColumn, line, endColumn);
				let diagnostic = new vscode.Diagnostic(range, error.msg, mapSeverityToVSCodeSeverity(error.severity));

				let diagnostics = diagnosticMap.get(targetUri);
				if (!diagnostics) {
					diagnostics = [];
				}

				diagnostics.push(diagnostic);
				diagnosticMap.set(targetUri, diagnostics);
			});

			let entries: [vscode.Uri, vscode.Diagnostic[]][] = [];
			diagnosticMap.forEach((diags, uri) => {
				entries.push([uri, diags]);
			});

			diagnosticCollection.set(entries);
		}).catch(err => {
			vscode.window.showErrorMessage(err);
		});
	});
}
Example #8
0
export function activate(context: ExtensionContext) {

	// The server is implemented in node
	let serverModule = context.asAbsolutePath(path.join('server', 'server.js'));

	// The debug options for the server
	let debugOptions = { execArgv: ["--nolazy", "--debug=6004"] };

	// If the extension is launch in debug mode the debug server options are use
	// Otherwise the run options are used
	let serverOptions: ServerOptions = {
		run : { module: serverModule },
		debug: { module: serverModule, options: debugOptions }
	};

	// Options to control the language client
	let clientOptions: LanguageClientOptions = {
		// Register the server for php documents
		documentSelector: ['php'],
		synchronize: {
			// Synchronize the setting section 'phpcs' to the server
			configurationSection: 'phpcs',
			// Notify the server about file changes to 'phpcs.xml' files contain in the workspace
			fileEvents: workspace.createFileSystemWatcher('**/phpcs.xml')
		}
	};

	// Create the language client the client.
	let client = new LanguageClient('PHP CodeSniffer Linter', serverOptions, clientOptions);

	// Create the save handler.
	let saveHandler = workspace.onDidSaveTextDocument(document => {
		if (document.languageId != `php`) {
			return;
		}
		let params: proto.TextDocumentIdentifier = { uri: document.uri.toString() };
		client.sendNotification<proto.TextDocumentIdentifier>(proto.DidSaveTextDocumentNotification.type, params);
	});

	let status = new PhpcsStatus();
	client.onNotification( proto.DidStartValidateTextDocumentNotification.type, (document) => {
		status.startProcessing(document.uri);
	});
	client.onNotification( proto.DidEndValidateTextDocumentNotification.type, (document) => {
		status.endProcessing(document.uri);
	});

	context.subscriptions.push(saveHandler);

	// Create the settings monitor and start the monitor for the client.
	let monitor = new SettingMonitor(client, 'phpcs.enable').start();

	// Push the monitor to the context's subscriptions so that the
	// client can be deactivated on extension deactivation
	context.subscriptions.push(monitor);
	context.subscriptions.push(status);
}
  constructor(newLineHandler: NewLineHandler) {
    this._newLineHandler = newLineHandler;

    // subscribe to events
    let subscriptions: Disposable[] = [];
    workspace.onDidSaveTextDocument(this._onEvent, this, subscriptions);

    this._disposable = Disposable.from(...subscriptions);
  }
Example #10
0
function createRsSaveWatcher() {
    if ( cmConfig.rsWatcherEnabled() ) {
        workspace.onDidSaveTextDocument( (e) => {
            if ( e.fileName.endsWith(".rs") ) {
                compilerAdapter.runIfStarted( `{ cm.rs.loadRs( cm.io.Url("${e.fileName.replace( /\\/g, "/" )}"), force=true ); }` );
            }
        });
    }
}