• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript vscode-languageserver-types.Position类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test

	test('WorkspaceEdit', () => {
		let workspaceChange = new WorkspaceChange();
		let uri = 'file:///abc.txt';
		let change1 = workspaceChange.getTextEditChange({uri: uri, version: 10});
		change1.insert(Position.create(0,1), 'insert');
		change1.replace(Range.create(0,1,2,3), 'replace');
		change1.delete(Range.create(0,1,2,3));
		let change2 = workspaceChange.getTextEditChange({ uri: 'file:///xyz.txt', version: 20 });
		change2.insert(Position.create(2,3), 'insert');

		let workspaceEdit = workspaceChange.edit;
		strictEqual(workspaceEdit.changes.length, 2);
		let edits = workspaceEdit.changes[0].edits;
		strictEqual(edits.length, 3);
		rangeEqual(edits[0].range, Range.create(0,1,0,1));
		strictEqual(edits[0].newText, 'insert');
		rangeEqual(edits[1].range, Range.create(0,1,2,3));
		strictEqual(edits[1].newText, 'replace');
		rangeEqual(edits[2].range, Range.create(0,1,2,3));
		strictEqual(edits[2].newText, '');

		edits = workspaceEdit.changes[1].edits;
		strictEqual(edits.length, 1);
		rangeEqual(edits[0].range, Range.create(2,3,2,3));
		strictEqual(edits[0].newText, 'insert');
	});
开发者ID:rlugojr,项目名称:vscode-languageserver-node,代码行数:26,代码来源:helpers.test.ts


示例2: test

	test('WorkspaceEdit', () => {
		let workspaceChange = new WorkspaceChange();
		let uri = 'file:///abc.txt';
		let change1 = workspaceChange.getTextEditChange(uri);
		change1.insert(Position.create(0,1), 'insert');
		change1.replace(Range.create(0,1,2,3), 'replace');
		change1.delete(Range.create(0,1,2,3));
		let change2 = workspaceChange.getTextEditChange('file:///xyz.txt');
		change2.insert(Position.create(2,3), 'insert');

		let workspaceEdit = workspaceChange.edit;
		let keys = Object.keys(workspaceEdit.changes);
		strictEqual(keys.length, 2);
		let edits = workspaceEdit.changes[uri];
		strictEqual(edits.length, 3);
		rangeEqual(edits[0].range, Range.create(0,1,0,1));
		strictEqual(edits[0].newText, 'insert');
		rangeEqual(edits[1].range, Range.create(0,1,2,3));
		strictEqual(edits[1].newText, 'replace');
		rangeEqual(edits[2].range, Range.create(0,1,2,3));
		strictEqual(edits[2].newText, '');

		edits = workspaceEdit.changes['file:///xyz.txt'];
		strictEqual(edits.length, 1);
		rangeEqual(edits[0].range, Range.create(2,3,2,3));
		strictEqual(edits[0].newText, 'insert');
	});
开发者ID:Blacklite,项目名称:vscode-languageserver-node,代码行数:27,代码来源:helpers.test.ts


示例3: _selectorCallSymbol

/**
 * Handler for selector call symbols
 * @param {Object} node
 * @param {String[]} text - text editor content splitted by lines
 * @return {SymbolInformation}
 */
function _selectorCallSymbol(node: StylusNode, text: string[]): SymbolInformation {
  const lineno = Number(node.lineno) - 1;
  const name = prepareName(text[lineno]);
  const column = Math.max(text[lineno].indexOf(name), 0);

  const posStart = Position.create(lineno, column);
  const posEnd = Position.create(lineno, column + name.length);

  return SymbolInformation.create(name, SymbolKind.Class, Range.create(posStart, posEnd));
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:16,代码来源:symbols-finder.ts


示例4: test

	test('inserts', function (): any {
		let input = TextDocument.create('foo://bar/f', 'html', 0, '012345678901234567890123456789');
		assert.equal(applyEdits(input, [TextEdit.insert(Position.create(0, 0), 'Hello')]), 'Hello012345678901234567890123456789');
		assert.equal(applyEdits(input, [TextEdit.insert(Position.create(0, 1), 'Hello')]), '0Hello12345678901234567890123456789');
		assert.equal(applyEdits(input, [TextEdit.insert(Position.create(0, 1), 'Hello'), TextEdit.insert(Position.create(0, 1), 'World')]), '0HelloWorld12345678901234567890123456789');
		assert.equal(applyEdits(input, [TextEdit.insert(Position.create(0, 2), 'One'), TextEdit.insert(Position.create(0, 1), 'Hello'), TextEdit.insert(Position.create(0, 1), 'World'), TextEdit.insert(Position.create(0, 2), 'Two'), TextEdit.insert(Position.create(0, 2), 'Three')]), '0HelloWorld1OneTwoThree2345678901234567890123456789');
	});
开发者ID:sameer-coder,项目名称:vscode,代码行数:7,代码来源:utils.test.ts


示例5: _functionSymbol

/**
 * Handler for function
 * @param {Object} node
 * @param {String[]} text - text editor content splitted by lines
 * @return {SymbolInformation}
 */
function _functionSymbol(node: StylusNode, text: string[]): SymbolInformation {
  const name = node.name;
  const lineno = Number(node.val!.lineno) - 1;
  const column = Math.max(text[lineno].indexOf(name), 0);

  const posStart = Position.create(lineno, column);
  const posEnd = Position.create(lineno, column + name.length);
  const range = Range.create(posStart, posEnd);

  return SymbolInformation.create(name, SymbolKind.Function, range);
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:17,代码来源:symbols-finder.ts


示例6: _selectorSymbol

/**
 * Handler for selectors
 * @param {Object} node
 * @param {String[]} text - text editor content splitted by lines
 * @return {SymbolInformation}
 */
function _selectorSymbol(node: StylusNode, text: string[]): SymbolInformation {
  const firstSegment = node.segments[0];
  const name = firstSegment.string
    ? node.segments.map(s => s.string).join('')
    : firstSegment.nodes!.map(s => s.name).join('');
  const lineno = Number(firstSegment.lineno) - 1;
  const column = node.column - 1;

  const posStart = Position.create(lineno, column);
  const posEnd = Position.create(lineno, column + name.length);
  const range = Range.create(posStart, posEnd);

  return SymbolInformation.create(name, SymbolKind.Class, range);
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:20,代码来源:symbols-finder.ts


示例7: it

    it("updates text document", async () => {
      let languageServer = await LanguageServer.startAndInitialize();
      await languageServer.sendNotification("textDocument/didOpen", {
        textDocument: Types.TextDocumentItem.create(
          "file:///test-document.txt",
          "txt",
          0,
          "Hello, World!"
        )
      });

      await languageServer.sendNotification("textDocument/didChange", {
        textDocument: Types.VersionedTextDocumentIdentifier.create(
          "file:///test-document.txt",
          1
        ),
        contentChanges: [{ text: "Hello again!" }]
      });

      let result = await languageServer.sendRequest("debug/textDocument/get", {
        textDocument: Types.TextDocumentIdentifier.create(
          "file:///test-document.txt"
        ),
        position: Types.Position.create(0, 0)
      });

      expect(result).toEqual("Hello again!");
      await LanguageServer.exit(languageServer);
    });
开发者ID:the-lambda-church,项目名称:merlin,代码行数:29,代码来源:TextDocument.test.ts


示例8: it

  it("returns type inferred under cursor (markdown formatting)", async () => {
    languageServer = await LanguageServer.startAndInitialize({
      textDocument: {
        hover: {
          dynamicRegistration: true,
          contentFormat: ["markdown", "plaintext"]
        }
      }
    });
    await languageServer.sendNotification("textDocument/didOpen", {
      textDocument: Types.TextDocumentItem.create(
        "file:///test.ml",
        "txt",
        0,
        "let x = 1\n"
      )
    });

    let result = await languageServer.sendRequest("textDocument/hover", {
      textDocument: Types.TextDocumentIdentifier.create("file:///test.ml"),
      position: Types.Position.create(0, 4)
    });

    expect(result).toMatchObject({
      contents: { kind: "markdown", value: "```ocaml\nint\n```" },
      range: {end: {character: 5, line: 0}, start: {character: 4, line: 0}},
    });
  });
开发者ID:the-lambda-church,项目名称:merlin,代码行数:28,代码来源:textDocument-hover.test.ts


示例9: provideCompletionItems

export function provideCompletionItems(document: TextDocument, position: Position): CompletionList {
  const start = document.offsetAt(Position.create(position.line, 0));
  const end = document.offsetAt(position);
  const text = document.getText();
  const currentWord = text.slice(start, end).trim();
  const value = isValue(cssSchema, currentWord);

  let completions: CompletionItem[] = [];

  if (value) {
    const values = getValues(cssSchema, currentWord);
    const symbols = getAllSymbols(text, currentWord, position).filter(
      item => item.kind === CompletionItemKind.Variable || item.kind === CompletionItemKind.Function
    );
    completions = completions.concat(values, symbols, builtIn);
  } else {
    const atRules = getAtRules(cssSchema, currentWord);
    const properties = getProperties(cssSchema, currentWord, false);
    const symbols = getAllSymbols(text, currentWord, position).filter(
      item => item.kind !== CompletionItemKind.Variable
    );
    completions = completions.concat(properties, atRules, symbols);
  }
  return {
    isIncomplete: false,
    items: completions
  };
}
开发者ID:tiravata,项目名称:vetur,代码行数:28,代码来源:completion-item.ts


示例10: test

 test('getChangedPosition #3', () => {
   let pos = Position.create(0, 1)
   let r = Range.create(addPosition(pos, 0, -1), pos)
   let edit = TextEdit.replace(r, 'a\nb\n')
   let res = getChangedPosition(pos, edit)
   expect(res).toEqual({ line: 2, character: -1 })
 })
开发者ID:illarionvk,项目名称:dotfiles,代码行数:7,代码来源:position.test.ts


示例11: it

  it("completes with invalid prefix is buggy", async () => {
    openDocument(outdent`
      let f = LL.
    `);

    let items = await queryCompletion(Types.Position.create(0, 11));
    expect(items).toMatchObject([]);
  });
开发者ID:the-lambda-church,项目名称:merlin,代码行数:8,代码来源:textDocument-completion.test.ts


示例12: it

 it('should return false for change to file not exists', async () => {
   let uri = URI.file('/tmp/not_exists').toString()
   let versioned = VersionedTextDocumentIdentifier.create(uri, null)
   let edit = TextEdit.insert(Position.create(0, 0), 'bar')
   let documentChanges = [TextDocumentEdit.create(versioned, [edit])]
   let res = await workspace.applyEdit({ documentChanges })
   expect(res).toBe(false)
 })
开发者ID:illarionvk,项目名称:dotfiles,代码行数:8,代码来源:workspace.test.ts


示例13: getDoc

 async function getDoc(languageServer) {
   let result = await languageServer.sendRequest("debug/textDocument/get", {
     textDocument: Types.TextDocumentIdentifier.create(
       "file:///test-document.txt"
     ),
     position: Types.Position.create(0, 0)
   });
   return result;
 }
开发者ID:the-lambda-church,项目名称:merlin,代码行数:9,代码来源:TextDocument.test.ts


示例14: async

 provideCompletionItems: async (
   _document: TextDocument,
   _position: Position,
   _token: CancellationToken,
   _context: CompletionContext
 ): Promise<CompletionItem[]> => {
   return [{
     label: 'foo',
     filterText: 'foo',
     additionalTextEdits: [TextEdit.insert(Position.create(0, 0), 'a\nbar')]
   }]
 }
开发者ID:illarionvk,项目名称:dotfiles,代码行数:12,代码来源:completion.test.ts


示例15: getValueAndRange

function getValueAndRange(document: TextDocument, currRange: Range): { value: string; range: Range } {
  let value = document.getText();
  let range = currRange;

  if (currRange) {
    const startOffset = document.offsetAt(currRange.start);
    const endOffset = document.offsetAt(currRange.end);
    value = value.substring(startOffset, endOffset);
  } else {
    range = Range.create(Position.create(0, 0), document.positionAt(value.length));
  }
  return { value, range };
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:13,代码来源:index.ts


示例16: it

  it("rename value in a file with documentChanges capability", async () => {
    languageServer = await LanguageServer.startAndInitialize({workspace: {workspaceEdit: {documentChanges: true}}});

    await openDocument(outdent`
      let num = 42
      let num = num + 13
      let num2 = num
    `);

    let result = await query(Types.Position.create(0, 4));

    expect(result).toMatchObject({
      "documentChanges": [
        {
          "textDocument": {
            "version": 0,
            "uri": "file:///test.ml"
          },
          "edits": [
            {
              "range": {
                "start": {
                  "line": 0,
                  "character": 4
                },
                "end": {
                  "line": 0,
                  "character": 7
                }
              },
              "newText": "new_num"
            },
            {
              "range": {
                "start": {
                  "line": 1,
                  "character": 10
                },
                "end": {
                  "line": 1,
                  "character": 13
                }
              },
              "newText": "new_num"
            }
          ]
        }
      ],
      "changes": null
    });
  });
开发者ID:the-lambda-church,项目名称:merlin,代码行数:51,代码来源:textDocument-rename.test.ts


示例17: it

  it("highlight references in a file", async () => {
    await openDocument(outdent`
      let num = 42
      let sum = num + 13
      let sum2 = sum + num
    `);

    let result = await query(Types.Position.create(0, 4));

    expect(result).toMatchObject([
      {
        range: {
          end: {
            character: 7,
            line: 0
          },
          start: {
            character: 4,
            line: 0
          }
        },
        kind: 1
      },
      {
        range: {
          end: {
            character: 13,
            line: 1
          },
          start: {
            character: 10,
            line: 1
          }
        },
        kind: 1
      },
      {
        range: {
          end: {
            character: 20,
            line: 2
          },
          start: {
            character: 17,
            line: 2
          }
        },
        kind: 1
      }
    ]);
  });
开发者ID:the-lambda-church,项目名称:merlin,代码行数:51,代码来源:textDocument-documentHighlight.test.ts


示例18: function

	let testCompletionFor = function (value: string, expected: { count?: number, items?: ItemDescription[], participant?: { onProperty?, onPropertValue?, onURILiteralValue?, onImportPath? } }, settings?: LanguageSettings) {
		let offset = value.indexOf('|');
		value = value.substr(0, offset) + value.substr(offset + 1);

		let actualPropertyContexts: { propertyName: string; range: Range; }[] = [];
		let actualPropertyValueContexts: { propertyName: string; propertyValue?: string; range: Range; }[] = [];
		let actualURILiteralValueContexts: { uriValue: string; position: Position; range: Range; }[] = [];
		let actualImportPathContexts: { pathValue: string; position: Position; range: Range; }[] = [];

		let ls = cssLanguageService.getCSSLanguageService();
		ls.configure(settings);

		if (expected.participant) {
			ls.setCompletionParticipants([{
				onCssProperty: context => actualPropertyContexts.push(context),
				onCssPropertyValue: context => actualPropertyValueContexts.push(context),
				onCssURILiteralValue: context => actualURILiteralValueContexts.push(context),
				onCssImportPath: context => actualImportPathContexts.push(context)
			}]);
		}

		let document = TextDocument.create('test://test/test.css', 'css', 0, value);
		let position = Position.create(0, offset);
		let jsonDoc = ls.parseStylesheet(document);
		let list = ls.doComplete(document, position, jsonDoc);
		if (typeof expected.count === 'number') {
			assert.equal(list.items, expected.count);
		}
		if (expected.items) {
			for (let item of expected.items) {
				assertCompletion(list, item, document, offset);
			}
		}
		if (expected.participant) {
			if (expected.participant.onProperty) {
				assert.deepEqual(actualPropertyContexts, expected.participant.onProperty);
			}
			if (expected.participant.onPropertValue) {
				assert.deepEqual(actualPropertyValueContexts, expected.participant.onPropertValue);
			}
			if (expected.participant.onURILiteralValue) {
				assert.deepEqual(actualURILiteralValueContexts, expected.participant.onURILiteralValue);
			}
			if (expected.participant.onImportPath) {
				assert.deepEqual(actualImportPathContexts, expected.participant.onImportPath);
			}
		}
	};
开发者ID:Microsoft,项目名称:vscode-css-languageservice,代码行数:48,代码来源:completion.test.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap