Permalink
Browse files

Updated OVERVIEW and EXAMPLES.

  • Loading branch information...
castwide committed Sep 7, 2018
1 parent bdcca67 commit 753c165571a41449a29cde777a2892ace378d751
Showing with 15 additions and 11 deletions.
  1. +7 −7 EXAMPLES.md
  2. +8 −4 OVERVIEW.md
@@ -16,15 +16,14 @@ pins = api_map.get_methods('String') # Get public instance methods of the String
```Ruby
api_map = Solargraph::ApiMap.new
source = Solargraph::Source.load_string('class MyClass; end', 'my_class.rb')
api_map.virtualize source # Add the source to the map
api_map.map source # Add the source to the map
pins = api_map.get_constants('') # The constants in the global namespace will include `MyClass`
```

## Adding a Workspace to an ApiMap

```Ruby
workspace = Solargraph::Workspace.new('/path/to/project')
api_map = Solargraph::ApiMap.new(workspace)
api_map = Solargraph::ApiMap.load('/path/to/workspace')
pins = api_map.get_constants('') # Results will include constants defined in the project's code
```

@@ -34,16 +33,17 @@ pins = api_map.get_constants('') # Results will include constants defined in the
api_map = Solargraph::ApiMap.new
source = Solargraph::Source.load_string("var = 'a string'; puts var", 'example.rb')
api_map.virtualize source
fragment = source.fragment_at(0, 23)
pins = api_map.define(fragment) # `var` is recognized as a local variable containing a String
clip = api_map.clip_at('example.rb', Solargraph::Position.new(0, 23))
pins = clip.define # `var` is recognized as a local variable containing a String
```

## Querying Completion Suggestions
```Ruby
api_map = Solargraph::ApiMap.new
source = Solargraph::Source.load_string("String.", 'example.rb')
fragment = source.fragment_at(0, 7)
completion = api_map.complete(fragment) # Suggestions will include String class methods
api_map.map source
clip = api_map.clip_at('example.rb', Solargraph::Position.new(0, 7))
completion = clip.complete # Suggestions will include String class methods
```

## Adding a Message to the Language Server Protocol
@@ -8,15 +8,19 @@ The Solargraph library consists of two major groups of components: the data prov

**Workspace** (`Solargraph::Workspace`): A collection of Sources that comprise a project. Workspaces have configurations that define which files to include in maps and other project-related options. Users can configure the Workspace through a .solargraph.yml file in a project's root directory.

**Source** (`Solargraph::Source`): Data about a single Ruby file. Sources parse Ruby code into an AST and generate a collection of Pins.
**Source** (`Solargraph::Source`): Data about a single Ruby file. Sources parse Ruby code into an AST and handle incremental updates.

**Pins** (`Solargraph::Pin`): Information about a class, a module, a method, a variable, etc. Pins for different types of components extend `Pin::Base`. Most ApiMap queries return results as an array of Pins.
**SourceMap** (`Solargraph::SourceMap`): A Source with generated pins for use in ApiMaps.

**Fragment** (`Solargraph::Source::Fragment`): Information about a specific location in a Source. ApiMaps use fragments to gather contextual program data, such as local variables that are visible from the fragment's location or methods that are available within the location's scope.
**Pins** (`Solargraph::Pin`): Information about classes, modules, methods, variables, etc. Pins for different types of components extend `Pin::Base`. Most ApiMap queries return results as an array of Pins.

**Cursor** (`Solargraph::Source::Cursor`): Information about a specific location in a Source.

**Clip** (`Solargraph::SourceMap::Clip`): A Cursor bundled with an ApiMap to provide definitions, completions, and other information.

**YardMap** (`Solargraph::YardMap`): A collection of YARD documents. ApiMaps use YardMaps to gather data from external gems and the Ruby core.

**Library** (`Solargraph::Library`): The component that synchronizes a Workspace with its associated ApiMap. Libraries help ensure that the ApiMap gets updated when a file in the Workspace changes.
**Library** (`Solargraph::Library`): The component that synchronizes a Workspace with an ApiMap. Libraries help ensure that the ApiMap gets updated when a file in the Workspace changes.

## Language Servers

0 comments on commit 753c165

Please sign in to comment.