当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript TextDocuments.onDidOpen方法代码示例

本文整理汇总了TypeScript中vscode-languageserver.TextDocuments.onDidOpen方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextDocuments.onDidOpen方法的具体用法?TypeScript TextDocuments.onDidOpen怎么用?TypeScript TextDocuments.onDidOpen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vscode-languageserver.TextDocuments的用法示例。


在下文中一共展示了TextDocuments.onDidOpen方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: constructor

	constructor() {
		this.documents = new TextDocuments();
		this.subject = new Subject<DocumentEvent>();

		this.documents.onDidOpen(this.emitDocumentEvent(DocumentEventKind.OPEN));
		this.documents.onDidChangeContent(this.emitDocumentEvent(DocumentEventKind.CHANGE_CONTENT));
		this.documents.onDidClose(this.emitDocumentEvent(DocumentEventKind.CLOSE));
	}
开发者ID:rubyide,项目名称:vscode-ruby,代码行数:8,代码来源:DocumentManager.ts

示例2: constructor

  constructor(
      connection: IConnection, documents: TextDocuments, baseDir: string,
      converter: AnalyzerLSPConverter, logger: Logger) {
    super();
    const fileLoader = new FsUrlLoader(baseDir);
    const inMemoryOverlayLoader = new InMemoryOverlayUrlLoader(fileLoader);
    this.inMemoryDocuments = inMemoryOverlayLoader.urlContentsMap;
    this.urlLoader = inMemoryOverlayLoader;

    const {fire, stream} = EventStream.create<FileEvent[]>();
    this.fileChanges = stream;
    documents.onDidOpen((change) => {
      logger.log(`Opened: ${change.document.uri}`);
    });
    this.disposables.push(documents.onDidChangeContent((change) => {
      logger.log(`Changed in memory: ${change.document.uri}`);
      // A document has changed in memory!
      const url = converter.getAnalyzerUrl(change.document);
      if (!url) {
        return;  // don't care
      }
      this.inMemoryDocuments.set(url, change.document.getText());

      // Publish document change so other parts of the system can react.
      fire([{type: FileChangeType.Changed, uri: change.document.uri}]);
    }));

    this.disposables.push(documents.onDidClose((event) => {
      logger.log(`Closed: ${event.document.uri}`);
      // The file is no longer managed in memory, so we should delete it from
      // the in-memory map.
      const url = converter.getAnalyzerUrl(event.document);
      if (url === undefined) {
        return;  // don't care
      }
      this.inMemoryDocuments.delete(url);
      fire([{type: FileChangeType.Changed, uri: event.document.uri}]);
    }));

    connection.onDidChangeWatchedFiles((req) => {
      for (const change of req.changes) {
        logger.log(`Changed on disk: ${change.uri}`);
      }
      const inMemoryURIs = new Set(documents.keys());
      // We will get documents.onDidChangeContent events for changes of
      // in-memory buffers, so we filter them out to avoid sending duplicate
      // events for those changes.
      const diskBackedChanges =
          req.changes.filter((ch) => !inMemoryURIs.has(ch.uri));
      fire(diskBackedChanges);
    });
  }
开发者ID:MehdiRaash,项目名称:tools,代码行数:52,代码来源:file-synchronizer.ts

示例3: createConnection

import {
	createConnection, TextDocuments, ProposedFeatures, TextDocumentSyncKind
} from 'vscode-languageserver';

// Creates the LSP connection
let connection = createConnection(ProposedFeatures.all);

// Create a manager for open text documents
let documents = new TextDocuments();

// The workspace folder this server is operating on
let workspaceFolder: string;

documents.onDidOpen((event) => {
	connection.console.log(`[Server(${process.pid}) ${workspaceFolder}] Document opened: ${event.document.uri}`);
})
documents.listen(connection);

connection.onInitialize((params) => {
	workspaceFolder = params.rootUri;
	connection.console.log(`[Server(${process.pid}) ${workspaceFolder}] Started and initialize received`);
	return {
		capabilities: {
			textDocumentSync: {
				openClose: true,
				change: TextDocumentSyncKind.None
			}
		}
	}
});
开发者ID:voodoos,项目名称:vscode-extension-samples,代码行数:30,代码来源:server.ts

示例4: return

        if (!uri1.endsWith("/")) {
            uri1 += path.sep;
        }

        if (uri2.endsWith("/")) {
            uri2 += path.sep;
        }

        return (uri1.length - uri2.length);
    });
}

documents.onDidOpen(async (event) => {
    trace(`onDidOpen: ${event.document.uri}`);

    await validateTextDocument(event.document);
});

// The content of a text document has changed.
// This event is emitted when the text document is first opened or when its content has changed.
documents.onDidChangeContent(async (event) => {
    trace(`onDidChangeContent: ${event.document.uri}`);

    const settings = await settingsCache.get(event.document.uri);

    if (settings && settings.run === "onType") {
        await validateTextDocument(event.document);
    } else if (settings && settings.run === "onSave") {
        // Clear the diagnostics when validating on save and when the document is modified.
        connection.sendDiagnostics({uri: event.document.uri, diagnostics: []});
开发者ID:glen-84,项目名称:vscode-sass-lint,代码行数:30,代码来源:sass-lint-server.ts

示例5: runServer


//.........这里部分代码省略.........
		if (doc && ast) {
			req.arguments = args.length === 0 ? undefined : args;
			const edit = languageService.executeCommand(doc, ast, req);

			if (edit)
				connection.workspace.applyEdit(edit);
		}
	});

	/**
	 * Invoked when user renames something.
	 * TODO: Symbol Provider, so we can only rename symbols?
	 */
	connection.onRenameRequest(req => {
		const uri = req.textDocument.uri;
		const doc = documents.get(uri);
		const ast = ensureAst(uri, doc);
		if (doc && ast) {
			const r = languageService.renameSymbol(doc, ast, req.position, req.newName);
			return r ? r : invalidRequest();
		}
		return invalidRequest();
	});

	/**
	 * Update the current AST and send diagnostics.
	 */
	documents.onDidChangeContent(change => {
		const doc = change.document;
		const ast = updateAst(doc.uri, doc);
		if (ast === undefined) throw "This cannot happen";
		return validateDocument(doc, ast);
	});

	let currentSettings: DotLanguageServerSettings = { ...defaultSettings };

	// The settings have changed. Is send on server activation as well.
	connection.onDidChangeConfiguration(change => {
		const newSettings = (change.settings as Settings).dotLanguageServer;
		if (newSettings)
			currentSettings = newSettings;

		rebuildAll();
		validateAll();
	});

	function validateAll() {
		for (const uri of astOfFile.keys()) {
			const doc = documents.get(uri);
			if (doc) {
				const ast = ensureAst(uri, doc);
				if (ast)
					validateDocument(doc, ast);
			}
		}
	}
	function validateDocument(doc: lsp.TextDocument, sf: SourceFile): void {
		const diagnostics = languageService.validateDocument(doc, sf);
		connection.sendDiagnostics({ uri: doc.uri, diagnostics });
	}

	connection.onDidChangeWatchedFiles(_change => {
		// Monitored files have change in VSCode
		connection.console.log("We received an file change event");
	});

	/**
	 * Invoked when the user types and the editor requests a list of items to display for completion.
	 */
	connection.onCompletion(req => {
		const uri = req.textDocument.uri;
		const doc = documents.get(uri);
		const ast = ensureAst(uri, doc);
		return doc && ast
			? languageService.getCompletions(doc, ast, req.position)
			: invalidRequest();
	});

	/**
	 * Provide some details about the completion.
	 * TODO: Omit or implement.
	 */
	connection.onCompletionResolve((item: lsp.CompletionItem): lsp.CompletionItem => {
		if (item.data === 1) {
			item.detail = "TypeScript details";
			item.documentation = "TypeScript documentation";
		} else if (item.data === 2) {
			item.detail = "JavaScript details";
			item.documentation = "JavaScript documentation";
		}
		return item;
	});

	documents.onDidOpen(params => updateAst(params.document.uri, params.document));

	const cancelled = () => new rpc.ResponseError<void>(rpc.ErrorCodes.RequestCancelled, "Request cancelled");
	const invalidRequest = () => new rpc.ResponseError<void>(rpc.ErrorCodes.InvalidRequest, "Invalid request");

	connection.listen();
}
开发者ID:nikeee,项目名称:dot-language-server,代码行数:101,代码来源:server.ts


注:本文中的vscode-languageserver.TextDocuments.onDidOpen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。